Reputation: 85
Project: https://github.com/cgranthovey/SCNViewTest
The app has 2 VCs.
When I segue to the 2nd VC I set up the SCNScene with the code below.
override func viewDidLoad() {
super.viewDidLoad()
mySCNView.autoenablesDefaultLighting = true
mySCNView.allowsCameraControl = true
mySCNView.backgroundColor = UIColor.black
}
override func viewWillAppear(_ animated: Bool) {
let pyramid = SCNNode()
pyramid.geometry = SCNPyramid(width: 1, height: 2, length: 1)
pyramid.geometry?.firstMaterial?.diffuse.contents = UIColor.purple
pyramid.geometry?.firstMaterial?.diffuse.contents = UIColor.white
pyramid.position = SCNVector3(0, 0, 0)
pyramid.eulerAngles = SCNVector3(x: 0, y: 10, z: 180 * Float.pi)
let shapeScene = SCNScene()
shapeScene.rootNode.addChildNode(pyramid)
mySCNView.scene = shapeScene
}
If I then flick the image and have it spin, and while it's spinning I press the back button
@IBAction func backBtnPress(_ sender: AnyObject){
self.navigationController?.popViewController(animated: true)
}
I get a crash.
Thread 1: EXC_BAD_ACCESS (code=1, address=0x101f2210)
However if I wait for the spinning to stop and then press the back button there is no crash. Any ideas what's going on or how to fix this?
Upvotes: 2
Views: 258
Reputation: 6622
Per my suggestion, after you expanded the stack trace you see an interesting piece of information. Specifically, the code causing the crash seems related to the inertia system of the SCNView
's camera controller.
Attempting to stop the inertia before exiting the scene's view controller appears to mitigate the issue in my brief testing. In my experience with iOS 11, this crash only ever happened on the simulator for me, but I was using modal presentations. I think this is likely a bug in SCNCameraController
.
@IBAction func backBtnPress(_ sender: AnyObject){
chariotView.defaultCameraController.stopInertia()
self.navigationController?.popViewController(animated: true)
}
Upvotes: 1