[英]SCNAction.playAudio causes crash when nodes get deinitialized
We pinpointed the cause of the crash to the statement of using SCNAction.playAudio
in our game. 我们将崩溃的原因确定为在游戏中使用SCNAction.playAudio
的声明。 If any playAudio
statements get called in our game, the deinitialization of the SCNScene/SCNView would later randomly trigger this crash: 如果在我们的游戏中调用了任何playAudio
语句,则SCNScene / SCNView的取消初始化将在以后随机触发此崩溃:
How we play the audio: 我们如何播放音频:
func playAudioSource(from node: SCNNode, source audioSource: SCNAudioSource) {
node.runAction(SCNAction.playAudio(audioSource, waitForCompletion: false))
}
It shows the EXC_BAD_ACCESS
being at CPP3DAudioEngine::RemoveContext
. 它显示EXC_BAD_ACCESS
位于CPP3DAudioEngine::RemoveContext
。 We're developing for iOS 10.3 using SceneKit and Swift 3. 我们正在使用SceneKit和Swift 3为iOS 10.3开发。
You should provide more code to better understand what happen in your game but surely you can correct your function with: 您应该提供更多代码,以更好地了解游戏中发生的事情,但是可以肯定地,您可以使用以下方法来纠正功能:
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 launch of the action when the action it's already launched or in execution and check also if your node is already attached to it's parent (this can be useful, it depend from where you launch this code..) 这样可以防止在动作已启动或正在执行时启动该动作,并检查您的节点是否已附加到其父节点(这很有用,取决于您从何处启动该代码。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.