当 SCNCamera 旋转时,应用程序在后退按钮上崩溃
App crashes on Back button when SCNCamera is rotating
没有找到问题或答案所以自己发布。当我为我的 SCNView 启用 Allow camera control
时,我的应用程序崩溃,然后滑动以使相机开始旋转,然后按导航栏中的返回按钮。崩溃堆栈跟踪:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x18)
frame #0: 0x0000000113e3d94b libobjc.A.dylib`objc_msgSend + 11
frame #1: 0x00000001158a2eb6 SceneKit`__42-[SCNCameraController _setInertiaRunning:]_block_invoke.166 + 31
frame #2: 0x00000001173e33f7 libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #3: 0x00000001173e443c libdispatch.dylib`_dispatch_client_callout + 8
frame #4: 0x00000001173ef6f0 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 628
frame #5: 0x00000001149bbee9 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
frame #6: 0x0000000114980592 CoreFoundation`__CFRunLoopRun + 2402
frame #7: 0x000000011497f9b9 CoreFoundation`CFRunLoopRunSpecific + 409
frame #8: 0x00000001199a29c6 GraphicsServices`GSEventRunModal + 62
frame #9: 0x000000011029b5e8 UIKit`UIApplicationMain + 159
* frame #10: 0x000000010e6f73e7 ShowIt`main at AppDelegate.swift:13
frame #11: 0x0000000117460d81 libdyld.dylib`start + 1
frame #12: 0x0000000117460d81 libdyld.dylib`start + 1
所以消息发送到解除分配的相机和应用程序崩溃。
找到这个解决方案:
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if isMovingFromParentViewController {
// Prevent crash on back tap when camera rotates
scnView.pointOfView = nil
}
}
基本上只是在控制器弹出时将摄像机节点设置为 nil
。
没有找到问题或答案所以自己发布。当我为我的 SCNView 启用 Allow camera control
时,我的应用程序崩溃,然后滑动以使相机开始旋转,然后按导航栏中的返回按钮。崩溃堆栈跟踪:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x18)
frame #0: 0x0000000113e3d94b libobjc.A.dylib`objc_msgSend + 11
frame #1: 0x00000001158a2eb6 SceneKit`__42-[SCNCameraController _setInertiaRunning:]_block_invoke.166 + 31
frame #2: 0x00000001173e33f7 libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #3: 0x00000001173e443c libdispatch.dylib`_dispatch_client_callout + 8
frame #4: 0x00000001173ef6f0 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 628
frame #5: 0x00000001149bbee9 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
frame #6: 0x0000000114980592 CoreFoundation`__CFRunLoopRun + 2402
frame #7: 0x000000011497f9b9 CoreFoundation`CFRunLoopRunSpecific + 409
frame #8: 0x00000001199a29c6 GraphicsServices`GSEventRunModal + 62
frame #9: 0x000000011029b5e8 UIKit`UIApplicationMain + 159
* frame #10: 0x000000010e6f73e7 ShowIt`main at AppDelegate.swift:13
frame #11: 0x0000000117460d81 libdyld.dylib`start + 1
frame #12: 0x0000000117460d81 libdyld.dylib`start + 1
所以消息发送到解除分配的相机和应用程序崩溃。
找到这个解决方案:
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if isMovingFromParentViewController {
// Prevent crash on back tap when camera rotates
scnView.pointOfView = nil
}
}
基本上只是在控制器弹出时将摄像机节点设置为 nil
。