【发布时间】:2019-12-03 02:51:01
【问题描述】:
崩溃:
com.apple.scenekit.scnview-renderer (34):EXC_BAD_ACCESS(代码=1,地址=0x68)
在按下按钮时尝试删除节点时,我不断遇到错误的访问崩溃。在某些情况下,为了重现崩溃,车辆必须生成并删除 2 或 3 次。我利用 removeFromParentNode 函数,并将 SCNNode 的全局变量设置为 nil。
- 已尝试在 main 上调度队列。
- 尝试了异常和符号断点。
- 尝试深入了解分配/僵尸工具,但未发现明显的内存泄漏/释放。内存已正确释放。
- 尝试使用 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.
【问题讨论】: