gpt4 book ai didi

ios - 场景套件渲染器访问错误导致崩溃

转载 作者:行者123 更新时间:2023-11-29 05:34:25 29 4
gpt4 key购买 nike

崩溃:

com.apple.scenekit.scnview-renderer (34): EXC_BAD_ACCESS (code=1, address=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.

最佳答案

当渲染器委托(delegate)方法更新不同线程中的节点时,尝试在主线程中隐藏/取消隐藏 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)
}
}
}
......

关于ios - 场景套件渲染器访问错误导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57191579/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com