[英]Removing SCNNode nodes from scene.rootNode is causing a crash, in SceneKit
我試圖從我的場景中刪除一組代表路徑的節點。 它們是 SCNSphere 幾何節點和表示線的自定義幾何的組合,使用 SCNGeometrySource 和 SCNGeometryElement 創建。
我不會將這些節點保留在任何類型的數組中。 相反,我在場景中 rootNode 的節點樹的第一級搜索這些節點,通過它們的名稱,然后調用一個使它們淡出的動作序列,並且它們應該從根節點中移除自己。
代碼如下:
func clearPath() {
//
let disappear = SCNAction.fadeOut(duration: 0.1)
let remove = SCNAction.removeFromParentNode()
let sequence = SCNAction.sequence([disappear, remove])
if let pathNodesToRemove = pathNodes() {
//
for node in pathNodesToRemove {
//
node.removeAllActions()
node.runAction(sequence)
}
}
if let lineNodesToRemove = lineNodes() {
for node in lineNodesToRemove {
//
node.removeAllActions()
node.runAction(sequence)
}
}
path.removeAll()
}
在哪里:
func pathNodes() -> [SCNNode]? {
//
...
let nodes = rootNode.childNodes.filter { (node) -> Bool in
//
guard let name = node.name else { return false }
if name.hasPrefix(configurationComponent.id) &&
name.range(of:"_PATH") != nil {
return true
} else {
return false
}
}
return nodes
}
lineNodes() 函數基本相同。
我打開 Zombie Objects 來跟蹤錯誤來自哪里,但我總是得到相同的錯誤:對 SceneKit`C3DNodeRemoveFromParentNode 的引用作為線程上調用的最后一件事,以及 EXC_BAD_ACCESS(代碼 = 1,地址... )。
clearPath() 函數是整個應用程序中唯一被我稱為“RemoveFromParentNode”的地方。
節點上沒有物理實體,也不會保留在其他任何地方。
關於如何解決這個問題的任何想法?
編輯 28/4/18:
這是發生它的線程的崩潰報告。 看起來 removeObjectFromChildNodesAtIndex 被調用了兩次......
Thread 9 name: Dispatch queue: com.apple.scenekit.renderingQueue.Air_Relay.ARTCSCNView0x104126720
Thread 9 Crashed:
0 SceneKit 0x00000001957d668c C3DNodeRemoveFromParentNode + 40
1 SceneKit 0x0000000195826e28 -[SCNNode __removeObjectFromChildNodesAtIndex:] + 184
2 SceneKit 0x0000000195826e28 -[SCNNode __removeObjectFromChildNodesAtIndex:] + 184
3 SceneKit 0x0000000195827350 -[SCNNode removeFromParentNode] + 396
4 SceneKit 0x000000019593e9fc -[SCNActionRemove updateWithTarget:forTime:] + 92
5 SceneKit 0x0000000195907cb8 SCNCActionSequence::cpp_updateWithTargetForTime+ 2202808 (SCNNode*, double) + 316
6 SceneKit 0x00000001957bcfb0 SCNActionApply + 112
7 SceneKit 0x0000000195853d2c _applyActions + 236
8 CoreFoundation 0x00000001814dccbc __CFDictionaryApplyFunction_block_invoke + 24
9 CoreFoundation 0x00000001814c3f98 CFBasicHashApply + 132
10 CoreFoundation 0x00000001814cdb64 CFDictionaryApplyFunction + 288
11 SceneKit 0x0000000195853b5c C3DAnimationManagerApplyActions + 92
12 SceneKit 0x000000019583b054 -[SCNRenderer _update:] + 656
13 SceneKit 0x000000019583d018 -[SCNRenderer _drawSceneWithNewRenderer:] + 252
14 SceneKit 0x000000019583d69c -[SCNRenderer _drawScene:] + 84
15 SceneKit 0x000000019583daa0 -[SCNRenderer _drawAtTime:] + 728
16 SceneKit 0x00000001958e446c -[SCNView _drawAtTime:] + 512
編輯 30/04/18
我繼續向應用程序添加其他功能,在那里我需要使用 SCNAction.removeFromParentNode() 刪除節點。 我也隔離了這些以獨立於上述代碼導致問題。
隨着每個新節點的生成,這些在 SCNRendererDelegate 更新時被更頻繁地調用。
我還嘗試使用 SCNAction.run 塊直接在節點上使用 removeFromParentNode() ,並且發生了同樣的問題。
當您使用 SCNAction.removeFromParentNode() 時,您不會刪除節點,您必須刪除它自己的節點。 如果您刪除路徑或操作,您本質上是將值設為 nil,因此當調用路徑或操作時,現在有一個 nil 值並且它會崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.