Did not found question or answer so posting it myself. My app crashes when I have Allow camera control
enabled for my SCNView, then swipe so camera starts rotating and then press Back button in navigation bar. Crash stacktrace:
* 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
So message send to deallocated camera and app crashes.
Found this solution:
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if isMovingFromParentViewController {
// Prevent crash on back tap when camera rotates
scnView.pointOfView = nil
}
}
Basically just set camera node to nil
when controller pops.