SCNAction.playAudio crashes when nodes are de-initialized

We indicated the reason for the failure to approve the use of SCNAction.playAudio in our game. If any playAudio statements are called in our game, de-initializing SCNScene / SCNView will later randomly trigger this crash:

enter image description here

How do we play audio:

 func playAudioSource(from node: SCNNode, source audioSource: SCNAudioSource) { node.runAction(SCNAction.playAudio(audioSource, waitForCompletion: false)) } 

Indicates that EXC_BAD_ACCESS is located in CPP3DAudioEngine::RemoveContext . We are developing for iOS 10.3 using SceneKit and Swift 3.

+5
source share
1 answer

You should provide more code to better understand what is happening in your game, but you can fix your function:

 func playAudioSource(from node: SCNNode, source audioSource: SCNAudioSource) { if let _ = node.parent, node.action(forKey: "playAudio") == nil { node.runAction(SCNAction.playAudio(audioSource, waitForCompletion: false),forKey:"playAudio") } } 

This prevents the action from starting when the action is running or executing, and also checks if your node is already attached to its parent (this may be useful, it depends on where you run this code ..)

+4
source

Source: https://habr.com/ru/post/1266700/


All Articles