I am seeing a crash in SceneKit that I was not seeing before iOS 13.1.2.
I’ve traced the issue to the following function and cannot completely suss out what is causing the issue.
If I comment out the line which runs the action on the node, all is well.
I can run playAudio actions on other pre-existing nodes in the scene but when I simply want to have a one-shot sound play using the below function, the app crashes.
So my thought is that perhaps this has something to do with the way I am instantiating the node but I cannot think of another way to instantiate a node just to play a sound at a given position.
I’ve also tried using a recycled audio source but that makes no difference.
Might anyone have any ideas what might be going on in this code to cause a crash? It’s just not obvious to me, especially since this had worked flawlessly before the iOS updates.
I’ve included the back trace below.
Thanks so much for any help / ideas!
Have a great weekend!
Cheers!
func play(sound: String, atPosition: SCNVector3, volume: Float, pitch: Float, loops: Bool, positional: Bool) {
// Sources will be pre-loaded and recycled for the finished app
if let source = SCNAudioSource(fileNamed: "art.scnassets/"+sound)
{
source.volume = volume
source.rate = pitch
source.isPositional = positional
source.shouldStream = false
source.loops = loops
source.load()
let node = SCNNode()
node.name = "oneShot"
node.position = atPosition
scnScene.rootNode.addChildNode(node)
// node.runAction(SCNAction.sequence([SCNAction.playAudio(source, waitForCompletion: true), SCNAction.removeFromParentNode()]))
// This line causes the crash
node.runAction(SCNAction.playAudio(source, waitForCompletion: false))
}
}
objc_retain + 16
frame #1: 0x00000001bd5a90c4 AVFAudio
-[AVAudioPlayerNode didAttachToEngine:] + 140
frame #2: 0x00000001bd5b66e8 AVFAudioAVAudioEngineImpl::AttachNode(AVAudioNode*, bool) + 272
frame #3: 0x00000001bd5b2324 AVFAudio
-[AVAudioEngine attachNode:] + 80
frame #4: 0x00000001c4aea48c SceneKitCPP3DAudioContext::AddVoice(void const*) + 120
frame #5: 0x00000001c4aeacf0 SceneKit
CPP3DAudioEngine::AddVoice(void const*) + 192
frame #6: 0x00000001c49bd618 SceneKitC3DNodeAddAudioPlayer + 40
frame #7: 0x00000001c4a07924 SceneKit
-[SCNNode addAudioPlayer:] + 132
frame #8: 0x00000001c49325e0 SceneKitSCNCPlaySound::cpp_updateWithTargetForTime(SCNNode*, double) + 96
frame #9: 0x00000001c499c690 SceneKit
SCNActionApply + 112
frame #10: 0x00000001c4a2d7a4 SceneKit_applyActions + 236
frame #11: 0x00000001b0a8e1b8 CoreFoundation
-[NSFrozenDictionaryM __apply:context:] + 128
frame #12: 0x00000001c4a2d5c8 SceneKitC3DAnimationManagerApplyActions + 104
frame #13: 0x00000001c4a173e4 SceneKit
-[SCNRenderer _update:] + 576
frame #14: 0x00000001c4a19a04 SceneKit-[SCNRenderer _drawSceneWithNewRenderer:] + 200
frame #15: 0x00000001c4a19fbc SceneKit
-[SCNRenderer _drawScene:] + 48
frame #16: 0x00000001c4a1a350 SceneKit-[SCNRenderer _drawAtTime:] + 616
frame #17: 0x00000001c4ab46b8 SceneKit
-[SCNView _drawAtTime:] + 428
frame #18: 0x00000001c497ae38 SceneKit__69-[NSObject(SCN_DisplayLinkExtensions) SCN_setupDisplayLinkWithQueue:]_block_invoke + 56
frame #19: 0x00000001c4a7fe48 SceneKit
__36-[SCNDisplayLink _callbackWithTime:]_block_invoke + 64
frame #20: 0x0000000105726c04 libdispatch.dylib_dispatch_client_callout + 16
frame #21: 0x0000000105735888 libdispatch.dylib
_dispatch_lane_barrier_sync_invoke_and_complete + 124
frame #22: 0x00000001c4a7fdd8 SceneKit-[SCNDisplayLink _callbackWithTime:] + 232
frame #23: 0x00000001058f95f8 GPUToolsCore
-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168
frame #24: 0x00000001b73da514 QuartzCoreCA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 632
frame #25: 0x00000001b1acdeb0 IOKit
IODispatchCalloutFromCFMessage + 488
frame #26: 0x00000001b0ae96d4 CoreFoundation__CFMachPortPerform + 172
frame #27: 0x00000001b0b12e5c CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 56
frame #28: 0x00000001b0b12588 CoreFoundation__CFRunLoopDoSource1 + 444
frame #29: 0x00000001b0b0d45c CoreFoundation
CFRunLoopRun + 2168
frame #30: 0x00000001b0b0c8bc CoreFoundationCFRunLoopRunSpecific + 464
frame #31: 0x00000001b0e4c994 Foundation
-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228
frame #32: 0x00000001c497b214 SceneKit__71-[SCNView(SCNDisplayLink) _initializeDisplayLinkWithCompletionHandler:]_block_invoke + 456
frame #33: 0x00000001c497b45c SceneKit
__SCNRenderThread_start + 96
frame #34: 0x00000001b08b11ec libsystem_pthread.dylib`_pthread_start + 124just wanted to update my question to say that this issue has resolved itself after updating to iOS 13.2. -My thanks to Apple. :)