已为iOS SceneKit中的SCNNode取消分配(对象设置为nil)时过度释放

时间:2019-03-14 02:45:24

标签: ios xcode memory-management bounding-box scnnode

寻求帮助,如果因为我没有经验而很明显,请道歉。我的环境是Xcode 10.1和Swift。

weak var node = Label(geometry: label, labelType: labelType, index: index)
if node != nil {
     transformTextNodeCenter(for: node!) //move pivot to center
     node!.scale = SCNVector3(x: parameters.textScaleRatio, y: parameters.textScaleRatio, z: parameters.textScaleRatio) //rescale the textnode
     print(node!) //print no.1
     print(node!.labelType, node!.index, node!.boundingBox) //print no.2
     let textWidth = node!.boundingBox.max.x - node!.boundingBox.min.x //<- This is the line generate error
     let textHeight = node!.boundingBox.max.y - node!.boundingBox.min.y
     let maxWidth = max(textWidth, recordedWidth)
     node!.position = position + SCNVector3(x: extra.x * textWidth, y: extra.y * textWidth, z: extra.z * textWidth)
     node!.eulerAngles = eulerAngles
     node!.name = String("\(name)\(text)")
     self.label[labelArray].append(node!)
     //self.label.insert(node)
     self.addChildNode(node!)
} else {
    print("node == nil")
}

该函数的目的是将SCNText添加到我的场景中,但是有可能我的textnode将被释放在函数的中间(我将其放在for循环中,并且在崩溃前随机运行多个循环)请参见图片。 1

看起来节点已正确初始化,因为它可以通过if node != nil" statement,并按如下所示打印2号。

“第0行(最小值:__ C.SCNVector3(x:0.7861328,y:1.2421875,z:0.0),最大值:__ C.SCNVector3(x:18.325195,y:10.211914,z:0.0))”

这使我相信我已经成功接收了textnode的boundingBox。但是在下一行“让textHeight = node!.boundingBox.max.y-node!.boundingBox.min.y”失败。

当崩溃时,我尝试对其进行跟踪,它显示该节点的图片为nil。 2 &图片。 3.

我读了一些这样的文章,并按照说明在objc_overrelease_during_dealloc_error上设置断点,但它导致我进入“ SCNBoundingVolume.boundingBox.getter”

libswiftSceneKit.dylib(extension in SceneKit):__C.SCNBoundingVolume.boundingBox.getter : (min: __C.SCNVector3, max: __C.SCNVector3):
0x10205167c <+0>:  sub    sp, sp, #0x30             ; =0x30 
0x102051680 <+4>:  stp    x29, x30, [sp, #0x20]
0x102051684 <+8>:  add    x29, sp, #0x20            ; =0x20 
0x102051688 <+12>: nop    
0x10205168c <+16>: ldr    x8, #0x29d4               ; (void *)0x000000021e95aa28: SCNVector3Zero
0x102051690 <+20>: ldp    w9, w10, [x8]
0x102051694 <+24>: ldr    w8, [x8, #0x8]
0x102051698 <+28>: stp    w9, w10, [sp, #0x10]
0x10205169c <+32>: str    w8, [sp, #0x18]
0x1020516a0 <+36>: stp    w9, w10, [sp]
0x1020516a4 <+40>: str    w8, [sp, #0x8]
0x1020516a8 <+44>: nop    
0x1020516ac <+48>: ldr    x1, #0x2e9c               ; "getBoundingBoxMin:max:"
0x1020516b0 <+52>: add    x2, sp, #0x10             ; =0x10 
0x1020516b4 <+56>: mov    x3, sp
0x1020516b8 <+60>: mov    x0, x20
0x1020516bc <+64>: bl     0x102053310               ; symbol stub for: objc_msgSend
0x1020516c0 <+68>: ldr    w1, [sp, #0x18]
0x1020516c4 <+72>: ldr    x0, [sp, #0x10]
0x1020516c8 <+76>: ldr    w8, [sp]
0x1020516cc <+80>: ldur   x2, [sp, #0x4]
0x1020516d0 <+84>: bfi    x1, x8, #32, #32
0x1020516d4 <+88>: ldp    x29, x30, [sp, #0x20]
0x1020516d8 <+92>: add    sp, sp, #0x30             ; =0x30 
0x1020516dc <+96>: ret    

我找不到解释它的方法。

P.S。强var仍然会导致崩溃,但是带有不同的错误消息“ EXC_BAD_ACCESS”,如图4所示。

pic1 for crash

pic2 for nil node

pic3 for nil node

pic3 for strong var instead of weak

0 个答案:

没有答案