场景套件渲染器上的错误访问崩溃

时间:2019-07-24 21:36:01

标签: ios swift arkit

崩溃:

  

com.apple.scenekit.scnview-renderer(34):EXC_BAD_ACCESS(代码= 1,地址= 0x68)

在尝试删除按钮上的节点时,我一直遇到严重的访问崩溃。在某些情况下,为了重现撞车事故,必须重新生成并删除车辆2到3次。我利用removeFromParentNode函数,并将SCNNode的全局变量设置为nil。

  • 尝试在主服务器上调度队列。
  • 尝试了异常和符号断点。
  • 尝试跳入分配/僵尸工具,未发现明显的内存泄漏/释放。内存已正确释放。
  • 尝试使用SCNTransaction隐藏UI。

添加节点功能


    @IBAction func addCarToSceneView(_ sender: UITapGestureRecognizer) {

            if self.sharedCarNode == nil {
            //if there is no car spawned, activate haptic feedback.
            self.feedbackGenerator = UIImpactFeedbackGenerator()
            self.feedbackGenerator?.impactOccurred()

            //Get tap location
            let tapLocation = sender.location(in: self.sceneView)
            let hitTestResults = self.sceneView.hitTest(tapLocation, types: .existingPlane)

            //Get first hit from tap location and grab where plane and node intersect
            guard let firstHit = hitTestResults.first else {return}
            let translation = firstHit.worldTransform.translation
            let x = translation.x
            let y = translation.y
            let z = translation.z

            //Initiate the scene from file
            guard let carScene = SCNScene(named: "Avent.scn", inDirectory: "art.scnassets/Aventador", options: nil),

            let carNode = carScene.rootNode.childNode(withName: "Car", recursively: true) else { return }

            carNode.position = SCNVector3(x, y + 4, z - 10)

            //Drop car animation to detected plane
            let originalCarPosition = SCNVector3Make(x, y, z)

            let dropCar = SCNAction.move(to: originalCarPosition, duration: 0.5)
            carNode.runAction(dropCar)

            self.positionForRotation = originalCarPosition

            self.sceneView.scene.rootNode.addChildNode(carNode)

            self.sharedCarNode = carNode

            self.rotateButton.isEnabled = true

            }

            //Hide all Planes in view once a car is spawned
            for plane in self.planes {
                plane.isHidden = true
                }

        }

删除汽车功能:

@IBAction func deletePressed(_ sender: UIButton) {
        self.sharedCarNode?.removeFromParentNode()
        self.sharedCarNode = nil
        for plane in self.planes {
            plane.isHidden = false
        }
        self.scaleFactor.text = "Scale: 0%"
    }

错误消息:

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 1685, TID: 396634, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000020f3cf6f4 <redacted> + 56
5   CoreMotion                          0x0000000215b49d9c CoreMotion + 294300
6   CoreMotion                          0x0000000215b4a2cc CoreMotion + 295628
7   CoreMotion                          0x0000000215b4a1dc CoreMotion + 295388
8   CoreMotion                          0x0000000215b7801c CoreMotion + 483356
9   CoreMotion                          0x0000000215b78060 CoreMotion + 483424
10  CoreFoundation                      0x000000021015e27c <redacted> + 28
11  CoreFoundation                      0x000000021015db64 <redacted> + 276
12  CoreFoundation                      0x0000000210158e58 <redacted> + 2276
13  CoreFoundation                      0x0000000210158254 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x0000000210158f88 CFRunLoopRun + 84
15  CoreMotion                          0x0000000215b779f4 CoreMotion + 481780
16  libsystem_pthread.dylib             0x000000020fdd6908 <redacted> + 132
17  libsystem_pthread.dylib             0x000000020fdd6864 _pthread_start + 48
18  libsystem_pthread.dylib             0x000000020fddedcc thread_start + 4
2019-07-24 17:29:25.746570-0400 Portal[1685:396634] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 1685, TID: 396634, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000020f3cf6f4 <redacted> + 56
5   CoreMotion                          0x0000000215b49d9c CoreMotion + 294300
6   CoreMotion                          0x0000000215b4a2cc CoreMotion + 295628
7   CoreMotion                          0x0000000215b4a1dc CoreMotion + 295388
8   CoreMotion                          0x0000000215b7801c CoreMotion + 483356
9   CoreMotion                          0x0000000215b78060 CoreMotion + 483424
10  CoreFoundation                      0x000000021015e27c <redacted> + 28
11  CoreFoundation                      0x000000021015db64 <redacted> + 276
12  CoreFoundation                      0x0000000210158e58 <redacted> + 2276
13  CoreFoundation                      0x0000000210158254 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x0000000210158f88 CFRunLoopRun + 84
15  CoreMotion                          0x0000000215b779f4 CoreMotion + 481780
16  libsystem_pthread.dylib             0x000000020fdd6908 <redacted> + 132
17  libsystem_pthread.dylib             0x000000020fdd6864 _pthread_start + 48
18  libsystem_pthread.dylib             0x000000020fddedcc thread_start + 4
2019-07-24 17:29:48.348816-0400 Portal[1685:396639] [Graphics] UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once.

1 个答案:

答案 0 :(得分:0)

当渲染器委托方法更新其他线程中的节点时,尝试在主线程(由SCNNodes发布)中隐藏/取消隐藏IBAction时遇到类似的问题。您的源代码未显示在时间/渲染器更新功能中如何更改节点。

例如:

@IBAction func toggleAnchorGrid(_ sender: UIBarButtonItem) 
   {

    showGrid = !showGrid
    for node in self.grids{
         node.isHidden = self.showGrid ? false : true
    }


//MARK: - SceneView renderer delegate methods...

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {

    DispatchQueue.main.async {
        if self.showGrid {
            if let foundGrid = self.grids.filter({ $0.anchor.identifier == anchor.identifier }).first {
                foundGrid.update(anchor: anchor as! ARPlaneAnchor)
            }
        }
    }
......