Search code examples
iosswiftsprite-kitscenekitskscene

Catch/guard crash earlier for [SCNSpriteKitEventHandler touchesCancelled:withEvent:]?


Can someone help me identify why my app is crashing or how I can better catch the crash earlier to know what line of code is causing it?

This is the crash log from Crashlytics:

#0
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x188ecef70 objc_msgSend + 16
1  SceneKit                       0x19a486324 -[SCNSpriteKitEventHandler touchesCancelled:withEvent:] + 528
2  SceneKit                       0x19a5666c8 -[SCNView touchesCancelled:withEvent:] + 60
3  UIKit                          0x1904cde04 __98-[UIApplication _cancelViewProcessingOfTouches:withEvent:sendingTouchesCancelledToViewsOfTouches:]_block_invoke + 552
4  UIKit                          0x1903c4b44 -[UIApplication _cancelTouches:withEvent:includingGestures:notificationBlock:] + 908
5  UIKit                          0x1904cdb84 -[UIApplication _cancelViewProcessingOfTouches:withEvent:sendingTouchesCancelledToViewsOfTouches:] + 172
6  UIKit                          0x1908f76ec _UIGestureEnvironmentCancelTouches + 628
7  UIKit                          0x1908f7464 -[UIGestureEnvironment _cancelTouches:event:] + 52
8  UIKit                          0x19036c438 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1604
9  UIKit                          0x1908f6680 _UIGestureEnvironmentUpdate + 1100
10 CoreFoundation                 0x18a4320c0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
11 CoreFoundation                 0x18a42fcf0 __CFRunLoopDoObservers + 372
12 CoreFoundation                 0x18a430180 __CFRunLoopRun + 1024
13 CoreFoundation                 0x18a35e2b8 CFRunLoopRunSpecific + 444
14 GraphicsServices               0x18be12198 GSEventRunModal + 180
15 UIKit                          0x1903a57fc -[UIApplication _run] + 684
16 UIKit                          0x1903a0534 UIApplicationMain + 208
17 activeMaze                     0x1000f4b08 main (ArchiveKeys.swift:9)
18 libdispatch.dylib              0x1893415b8 (Missing)

This crash is only happening in distributed apps and I can't replicate when debugging so "Enable Zombie Objects" does not appear to be helping.

Thanks

Greg


Solution

  • The crash was from the way I was removing an SKScene (.overlaySKScene) from an SCNView:

    I was setting it to nil, this works 99% of the time and always works on the sim but it is not correct:

        maze3DScene.overlaySKScene = nil
    

    I should have been removing the SKScene from the parent SCNView the same way you remove a SCNNode:

        maze3DScene.overlaySKScene?.removeFromParent()
    

    Hopefully this helps someone else who might make the same mistake.