SceneKit crash when simply locking then unlocking device

This crashes every time:


Any app that uses a SCNView will crash when the device is locked then unlocked!


Steps to Reproduce:


-Launch Xcode

-File / New / Project / Game / SceneKit (note this template app has no audio)

-(objective C or Swift does not matter)

-Run the app on your device

-Lock then unlock the device

-Crash (

AVAudioEngineGraph - even though this app has no audio)


I have filed a bug.


iOS 10.1 does not fix the bug, as the crash still happens in iOS 10.1 beta 3 (14B71) released October 10, 2016


Only workaround I have found is to allow background audio (even though no audio is playing!), but in my app I do have audio, and I don't want to allow background audio (otherwise I'd have to manage pausing/unpausing the audio).

Accepted Answer

Hi ashort,


This is a known issue that will be fixed in 10.2. In the meantime another simpler workaround should work:

Trigger the audio engine creation yourself before entering the background (for example at setup).

You can trigger this simply by getting the audio engine from the SCNView:


scnView.audioEngine;

thank you, and I like your workaround much better, I tested it and the workaround works.

Since this seems to be a fairly bad issue, and I haven't tested it yet, will 10.2 be out anytime soon to alleviate the issue?

It appears that doing this stops (and prevents) background audio playback by other apps when the SceneKit app is running.

Hi,


It seems we are still getting this error even on iOS 10.2. We even implemented the suggested workaround. below is our code right now. Can you tell us if this issue should have been fixed after iOS 10.2?



do {
     try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
} catch _ {}
    
if #available(iOS 9.0, *) {
     let scnView = SCNView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
     audioEngine = scnView.audioEngine
}


Note that the stacktrace we are getting on iOS 10.2 is slightly different. Instead of the crash originating in [SCNView _enterBackground:] it is now coming from [SCNView _enterForeground:]

SceneKit crash when simply locking then unlocking device
 
 
Q