SpriteKit playSoundFileNamed crash on iOS 8.3 - ios

I'm seeing some small amounts of SpriteKit playSoundFileNamed crashes from my app's crash log. The crashes happen on iOS 8.3.
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 CoreFoundation -[NSException initWithCoder:]
3 SpriteKit +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:]
4 SpriteKit +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:]
...
And a few related crashes:
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 CoreFoundation -[NSException raise:format:]
3 SpriteKit +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:]
4 SpriteKit +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:]
...
Does anyone know what causes this crash and how to fix it? Should I wrap every calls to playSoundFileNamed: in a try-catch block?
Edited
More information:
I'm using Swift. Trying to play my own sounds and I'm seeing the crashes coming from different sounds. I'm also seeing a couple reports from iOS 8.2 so this crash might not be iOS 8.3 specific.
The lines that play the sound:
var sound = SKAction.playSoundFileNamed("Sound/ABC.mp3", waitForCompletion: false)
self.runAction(sound)

I experienced a similar issue a while back. The issue was that the variable could not be made quickly enough to play as I was creating the variable each time the user tapped on the screen. Try defining the action in didMoveToView, and seeing if you still get the issue.
Hope that helps

Try this and let me know if its working.
var audioPlayer = AVAudioPlayer()
func playAudio() {
// Set the sound file name & extension
let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("ABC", ofType: "mp3")!)
// Preperation
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
try! AVAudioSession.sharedInstance().setActive(true)
// Play the sound
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound)
audioPlayer.prepareToPlay()
audioPlayer.play()
} catch {
print("there is \(error)")
}
}

I had similar problem. My game (swift + spritekit) was crashing indeterministic on iOS 8.x. but on 9.x works perfect. Piece of log:
2015-12-15 21:27:40.827 MyGame[24055:2285857]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Resource assets/mfx/my_sound.m4a can not be loaded'
*** First throw call stack:
(
0 CoreFoundation 0x008ae746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02598a97 objc_exception_throw + 44
2 CoreFoundation 0x008ae66d +[NSException raise:format:] + 141
3 SpriteKit 0x011ca435 +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:] + 628
4 SpriteKit 0x011601b4 +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:] + 78
5 MyGame 0x0012eb25
Solution is: load all sounds only once, as a constants (let). Do not create variable each time you want to play the sound.
import SpriteKit
import AVFoundation
class Sounds
{
static let SOUND1 = SKAction.playSoundFileNamed("assets/sound1.m4a", waitForCompletion: false)
static let SOUND2 = SKAction.playSoundFileNamed("assets/sound2.m4a", waitForCompletion: false)
}
Then, in some SKSpriteNode for example:
func playSound1()
{
self.runAction(Sounds.SOUND1)
}
Find similar / same issue here: Skaction.playsoundfilenamed crashes when repeat - sprite kit

Related

AudioKit crash: required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode

We are experiencing an exception in our project:
2019-08-08 10:18:28.703708-0600 AppName[99385:5069475] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ee2e8db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010e21bac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010ee2e662 +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x0000000111b94dbc _Z19AVAE_RaiseExceptionP8NSStringz + 156
4 AVFAudio 0x0000000111bf3937 _Z11_AVAE_CheckPKciS0_S0_b + 295
5 AVFAudio 0x0000000111b8cb8f _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1031
6 AVFAudio 0x0000000111bfb598 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194
7 AVFAudio 0x0000000111bfb5ff -[AVAudioEngine connect:to:format:] + 83
8 AppName 0x000000010a424c10 $s8AudioKitAAC6outputAA6AKNodeCSgvWZTf4dd_n + 2576
9 AppName 0x000000010a4230fd $s8AudioKitAAC6outputAA6AKNodeCSgvsZ + 93
10 AppName 0x000000010a2ba3a3 $s6AppName7MaestroC17setUpTrackPlayers7fileURLy10Foundation0H0V_tF + 1235
Examining the common gotchas video I see a similar exception being thrown, required condition is false: !nodeMixerConns.empty() && !hasDirectConnToIONode, which is caused by allowing the variables to go out of scope rather than be retained in the class.
So this occurs when we create an AKPlayer, which is retained in a class, then we create an AKTimePitch with this player which is also retained in that class, and finally assign that to AudioKit.output which triggers the exception. After that we were storing the class that holds onto the player and time pitch in an array, so I tried to move this up after it's created in hopes that was the issue, but I see the same exception.
Interestingly, this code works fine initially when we load up the first song but crashes when we hit the next button to load up the next song.
final class Maestro : NSObject {
static let shared = Maestro()
var audioPlayers = [TrackPlayer]()
func setUpTrackPlayers(fileURL: URL) {
let playerOne = TrackPlayer(url: fileURL)
audioPlayers.append(playerOne)
AudioKit.output = playerOne.handleMixerChain() //boom
do {
try AudioKit.start()
} catch {
print("Maestro AudioKit.start error: \(error)")
}
}
func next() {
for player in audioPlayers {
player.stop()
}
audioPlayers.removeAll()
setUpTrackPlayers(fileURL: newSong.getFileUrl())
}
}
final class TrackPlayer {
let player : AKPlayer
lazy var timePitch = AKTimePitch()
init(url: URL) {
player = AKPlayer(url: url)!
}
func handleMixerChain(pitch: Double = 0.0, tempo: Double = 1.0) -> AKTimePitch {
timePitch = AKTimePitch(player)
timePitch.pitch = pitch
timePitch.rate = tempo
return timePitch
}
}
Any ideas? If you need any more info let me know. May be good to note we are updating from AudioKit 4.5.5 where we didn't experience this crash.
I've opened the project and it seems like you're being a bit too relaxed about your set up / tear down of the signal chain. You're setting up AudioKit's output using local variables, never tearing down this signal chain, and then coming back resetting the AudioKit output and telling AudioKit to start without ever calling AudioKit.stop().

iOS crash Assertion Failure on CBPeripheralManager AddService:

I am facing crash issue on iOS CoreBluetooth's
[CBPeripheralManager AddService:].
Seems it occurred due to assertion failure in addService method. Tried so many ways, still can't figure out the issue.
As per my understanding this is not null pointer exception as I already tested passing nil value as AddService parameter which yield different issue.
I have implemented all the delegates of CBPeripheralManager including CBCentral delegates.
In general it works fine. Normally I can't reproduce this issue with intention. But it occurs suddenly.
Please help
.
Crash log:
0 CoreFoundation 0x18b3cafe0 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x189e2c538 objc_exception_throw + 56
2 CoreFoundation 0x18b3caeb4 +[NSException raise:format:arguments:] + 104
3 Foundation 0x18be62720 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4 CoreBluetooth 0x1922ab420 -[CBPeripheralManager addService:] + 820
5 MyApp 0x10110e1f4 -[MyPeripheralManager addServiceIntoPeripheralManager] (MyPeripheralManager.m:202)
Code Snipet:
-(void)addService{
if (!isServiceAdded) {
CLLog("Add Service timer started");
[backgroundTaskManager manageBackgroundRunningTask];
/*
AddService will be called after 5 seconds
when application launching finished or iOS BT on
*/
[self performSelector:#selector(addServiceIntoPeripheralManager) withObject:self afterDelay:SERVICE_ADDING_DELAY]; // 5 secs
} else {
CLDbg("Service already added");
}
}
- (void)addServiceIntoPeripheralManager{
CLLog("Add Service timer expired");
CLDbg("Service Adding: %#", [UUIDString]);
[cbPeripheralManager addService:Service];
}
Thanks in advance.
You are not implementing the callback updates of your BluetoothManager
see this answer
and This answer
I hope this will help you

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Start date cannot be later in time than end date!'

I am using Alamofire and after several hours of my app running on the simulator I got a crash with this error.
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Start date cannot be later in time than end date!'
I got this stack trace in console:
*** First throw call stack:
(
0 CoreFoundation 0x0000000111186d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000110be821e objc_exception_throw + 48
2 Foundation 0x00000001107f0e3c -[_NSConcreteDateInterval dealloc] + 0
3 CFNetwork 0x00000001131a18e8 -[__NSCFURLSessionTaskMetrics _initWithTask:] + 868
4 CFNetwork 0x00000001131a1497 -[NSURLSessionTaskMetrics _initWithTask:] + 100
5 CFNetwork 0x0000000112f77bc7 -[__NSCFURLLocalSessionConnection _tick_finishing] + 351
6 libdispatch.dylib 0x00000001128e3978 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x000000011290d0cd _dispatch_client_callout + 8
8 libdispatch.dylib 0x00000001128eae17 _dispatch_queue_serial_drain + 236
9 libdispatch.dylib 0x00000001128ebb4b _dispatch_queue_invoke + 1073
10 libdispatch.dylib 0x00000001128ee385 _dispatch_root_queue_drain + 720
11 libdispatch.dylib 0x00000001128ee059 _dispatch_worker_thread3 + 123
12 libsystem_pthread.dylib 0x0000000112cbc736 _pthread_wqthread + 1299
13 libsystem_pthread.dylib 0x0000000112cbc211 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Did someone get the similar crash?
Thanks
I had the same crash and did some research today and found this:
http://www.openradar.me/28301343
It looks Apple fixed the issue in iOS 10.2. just thought it may help you!
Yes I just got the same exact crash. It happened in a background thread and it seems to have to do with making a URL session network request. I wonder if it's some sort of multithreading bug having to do with the fact that I'm making two network requests at the same time. I'm using Alamofire as well but not sure if the bug lies in Alamofire or in Apple's code. I've been unable to reproduce it as of now. Maybe you can figure out how to reproduce it and then file an issue in Apple's bug radar or in the Alamofire GitHub repo.
This is a bug in Apple's NSURLSessionTaskMetrics code and happens during a network request when the user's clock gets moved far enough backwards that the request start timestamp is after the request end timestamp. This is reproducible using a network debugging proxy and manually adjusting the clock, and only occurs from iOS 10.0 up to but not including iOS 10.2
If you're using Alamofire, and you don't need NSURLSessionTaskMetrics, you can work around this by using a custom SessionDelegate for your SessionManager and overriding the responds(to aSelector..) function e.g:
class MySessionDelegate: Alamofire.SessionDelegate {
override public func responds(to aSelector: Selector) -> Bool {
let result: Bool = super.responds(to: aSelector)
if #available(iOS 10.2, *) {
// NSURLSessionTaskMetrics date crash is fixed
return result
} else if #available(iOS 10.0, *) {
// NSURLSessionTaskMetrics date crash is not fixed, turn off metric collection
if aSelector == #selector(self.urlSession(_:task:didFinishCollecting:)) {
return false
} else {
return result
}
} else {
// NSURLSessionTaskMetrics doesn't exist
return result
}
}
}
If you're using the default SessionManager (e.g. calling Alamofire.request(...)) you can create your own SessionManager instead in order to use your custom SessionDelegate:
let sessionManager: Alamofire.SessionManager = {
let configuration: URLSessionConfiguration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders
return Alamofire.SessionManager(configuration: configuration, delegate: MySessionDelegate(), serverTrustPolicyManager: nil)
}()
And now instead of calling Alamofire.request(...) you'd call sessionManager.request(...)
I have been struggling with this problem in an os x application for the last few months and have found a workaround.
Background:
Like the OP am using Alamofire to request JSON data via a Timer to send requests several times per second. The data comes in as expected however I get random crashes at irregular intervals with the same message as the OP i.e. Start date cannot be later in time than end date! etc etc.
Solution:
Rather than send Alamofire requests at a regular interval I added some logic which checks for a return of the previous request before sending the next one. This completely eliminated the random crashes.
Hope it helps :)
#thierryb

'NSConcreteMutableAttributedString initWithString:: nil value' when using Google Nearby Messages

I was following Google's documentation for using NearbyMessages API. I'm using Swift3. I have the following code to set up the app to publish to nearby.
let messageManager = GNSMessageManager(apiKey: "someky")
var publication: GNSPublication?
let message = GNSMessage(content:"name".data(using: .utf8))
if let messageManager = messageManager, let message = message {
publication = messageManager.publication(with:message)
}
I ran the app on the simulator. Then the app crashes in the 5th line (The line in the if-let block). Here's part of the stack trace:
(
0 CoreFoundation 0x000000011302334b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011271e21e objc_exception_throw + 48
2 CoreFoundation 0x000000011308c265 +[NSException raise:format:] + 197
3 Foundation 0x0000000112229fdc -[NSConcreteMutableAttributedString initWithString:] + 129
4 ProjectLibs 0x000000011879b55a gns_localizedAllowAppToConnectAttributedString + 415
5 ProjectLibs 0x000000011879b8b9 gns_localizedAllowAppToConnectString + 75
6 ProjectLibs 0x000000011879ae9f gcp_verifyDealloc + 24324
)
Since the messageManager and the message are both protected by the if-let block, I cannot find where is the nil exception coming from. Does anyone know why would there be a nil value in this block of code?
Thank you very much!
Does it work on a device? There is a bug in Nearby Messages 1.1.0 that causes a nil pointer exception on the simulator when you use BLE as a discovery medium.
Apologies! We'll get the bug fixed in the next release.

Xcode 6.1 with Swift: Terminating app due to uncaught exception 'NSUnknownKeyException'

First of all, I am new to Swift/iOS development and just started learning. I am trying to create a simple app that plays/pauses music. The interface has a play and pause buttons, and slider to control the music volume. I have searched SO and found some similar posts, but haven't found them helpful in my situation.
When I build and start the app in Xcode, I got the errors:
2015-04-07 23:04:25.403 Music Player[8772:102170] *** Terminating app due
to uncaught exception 'NSUnknownKeyException', reason:
'[<Music_Player.ViewController 0x7f991ad3a160> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key play.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a45bf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bf9fbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010a45bb79 -[NSException raise] + 9
3 Foundation 0x000000010a8737b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010a3a5e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010afacc7d -[UINib instantiateWithOwner:options:] + 1506
.....
22 UIKit 0x000000010ace7420 UIApplicationMain + 1282
23 Music Player 0x0000000109f24afe top_level_code + 78
24 Music Player 0x0000000109f24b3a main + 42
25 libdyld.dylib 0x000000010c779145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I use the AVAudioPlayer class to instantiate a player for playing and pausing music.
var player: AVAudioPlayer = AVAudioPlayer()
#IBAction func play(sender: AnyObject) {
var audioPath = NSString(string: NSBundle.mainBundle().pathForResource("music", ofType: "mp3")!) //file: music.mp3
var error: NSError? = nil
//instantiate the player
player = AVAudioPlayer(contentsOfURL: NSURL(string: audioPath), error: &error) //error pointer
player.prepareToPlay()
player.play()
}
#IBAction func pause(sender: AnyObject) {
player.pause()
}
I haven't done anything yet with the slider other than the below code:
#IBOutlet var slider: UISlider!
#IBAction func sliderChanged(sender: AnyObject) {
}
the GUI is attached below:
if let resourceUrl = NSBundle.mainBundle().URLForResource("1", withExtension: "mp3") {
if NSFileManager.defaultManager().fileExistsAtPath(resourceUrl.path!) {
var error: NSError? = nil
//instantiate the player
player = AVAudioPlayer(contentsOfURL: resourceUrl, error: &error)
player.prepareToPlay()
player.play()
}
}
Update your code like this for avoid crashing if file is not there.
this class is not key value coding-compliant for the key play.
Means If you have a control in your nib (xib file) that is linked to a property (IBOutlet) or method (IBAction) in your view controller, and you have either deleted or renamed the property or method, the runtime can't find it because it has been renamed and therefore crashes.
HERE I created complete working project for you.

Resources