iOS crash when device sleeps

We’ve found a crash in our iOS build after upgrading to 1.2.185, that we think is caused by the OS auto-locking the screen (or waking from that). I only have a single crash in TestFlight, and this device is on iOS 13.6, with low power mode enabled - the battery level was at 3% at the time.

I’m going to try getting console output from a debug build.

Main thread callstack:

    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Note:  EXC_CORPSE_NOTIFY
    Triggered by Thread:  0
    Thread 0 name:
    Thread 0 Crashed:
    0   libsystem_kernel.dylib        	0x00000001b1efad88 __pthread_kill + 8
    1   libsystem_pthread.dylib       	0x00000001b1e131e8 pthread_kill$VARIANT$mp + 136 (pthread.c:1458)
    2   libsystem_c.dylib             	0x00000001b1d669b0 __abort + 112 (abort.c:147)
    3   libsystem_c.dylib             	0x00000001b1d66940 abort + 112 (abort.c:118)
    4   libsystem_c.dylib             	0x00000001b1d65d54 __assert_rtn + 288 (assert.c:96)
    5   <game name>                    	0x00000001012d850c -[EAGLView destroyFramebuffer] + 3736844 (EAGLView.m:243)
    6   <game name>                    	0x00000001012d81d0 -[EAGLView layoutSubviews] + 3736016 (EAGLView.m:188)
    7   UIKitCore                     	0x00000001b666d7fc -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2144 (UIView.m:17176)
    8   QuartzCore                    	0x00000001b8c0a494 -[CALayer layoutSublayers] + 284 (CALayer.mm:9644)
    9   QuartzCore                    	0x00000001b8c105ec CA::Layer::layout_if_needed(CA::Transaction*) + 468 (CALayer.mm:9518)
    10  QuartzCore                    	0x00000001b8c1b128 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 140 (CALayer.mm:2468)
    11  QuartzCore                    	0x00000001b8b63b44 CA::Context::commit_transaction(CA::Transaction*, double) + 296 (CAContextInternal.mm:1992)
    12  QuartzCore                    	0x00000001b8b8d4e4 CA::Transaction::commit() + 676 (CATransactionInternal.mm:438)
    13  UIKitCore                     	0x00000001b61c2994 __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke_4 + 44 (UIApplication.m:7556)
    14  UIKitCore                     	0x00000001b61c1d70 -[UIApplication _performWithUICACommitStateSnapshotting:] + 184 (UIApplication.m:7400)
    15  UIKitCore                     	0x00000001b61c28cc __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke_2 + 552 (UIApplication.m:7555)
    16  UIKitCore                     	0x00000001b666016c +[UIView(Animation) performWithoutAnimation:] + 96 (UIView.m:13773)
    17  UIKitCore                     	0x00000001b61c266c __83-[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:]_block_invoke + 216 (UIApplication.m:7524)
    18  UIKitCore                     	0x00000001b57cf3fc -[UIScene _applyOverrideSettings:forActions:] + 116 (UIScene.m:1225)
    19  UIKitCore                     	0x00000001b63fef44 -[UIWindowScene _applySnapshotSettings:forActions:] + 76 (UIWindowScene.m:1112)
    20  UIKitCore                     	0x00000001b61c253c -[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:] + 380 (UIApplication.m:7521)
    21  UIKitCore                     	0x00000001b61c3ed8 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_3 + 124 (UIApplication.m:7727)
    22  FrontBoardServices            	0x00000001b72d3538 -[FBSSceneSnapshotAction _executeNextRequest] + 256 (FBSSceneSnapshotAction.m:135)
    23  FrontBoardServices            	0x00000001b72d358c -[FBSSceneSnapshotAction _executeNextRequest] + 340 (FBSSceneSnapshotAction.m:0)
    24  FrontBoardServices            	0x00000001b72d3128 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:] + 276 (FBSSceneSnapshotAction.m:87)
    25  UIKitCore                     	0x00000001b61c3e00 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_2 + 280 (UIApplication.m:7725)
    26  UIKitCore                     	0x00000001b61c3368 -[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:] + 1028 (UIApplication.m:7657)
    27  UIKitCore                     	0x00000001b61c3cc0 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke + 132 (UIApplication.m:7723)
    28  UIKitCore                     	0x00000001b57cf2f4 -[UIScene _enableOverrideSettingsForActions:] + 60 (UIScene.m:1208)
    29  UIKitCore                     	0x00000001b57cf574 -[UIScene _performSystemSnapshotWithActions:] + 120 (UIScene.m:1232)
    30  UIKitCore                     	0x00000001b61c3a3c -[UIApplication _performSnapshotsWithAction:forScene:completion:] + 468 (UIApplication.m:7722)
    31  UIKitCore                     	0x00000001b66fe908 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_3 + 168 (_UISceneSnapshotBSActionsHandler.m:54)
    32  UIKitCore                     	0x00000001b66fe790 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_2 + 468 (_UISceneSnapshotBSActionsHandler.m:70)
    33  UIKitCore                     	0x00000001b57ceb70 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 664 (UIScene.m:1057)
    34  UIKitCore                     	0x00000001b57cfb68 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220 (UIScene.m:1317)
    35  UIKitCore                     	0x00000001b5d55a08 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464 (UIApplicationSceneClientAgent.m:80)
    36  FrontBoardServices            	0x00000001b728d0a8 -[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528 (FBSSceneImpl.m:551)
    37  FrontBoardServices            	0x00000001b72b1684 __88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]_block_invoke_2 + 120 (FBSWorkspaceScenesClient.m:356)
    38  FrontBoardServices            	0x00000001b7296bfc -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 232 (FBSWorkspace.m:357)
    39  FrontBoardServices            	0x00000001b72b15b8 __88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]_block_invoke + 184 (FBSWorkspaceScenesClient.m:355)
    40  libdispatch.dylib             	0x00000001b1dcb524 _dispatch_client_callout + 16 (object.m:495)
    41  libdispatch.dylib             	0x00000001b1d74434 _dispatch_block_invoke_direct$VARIANT$mp + 224 (queue.c:466)
    42  FrontBoardServices            	0x00000001b72d5850 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40 (FBSSerialQueue.m:173)
    43  FrontBoardServices            	0x00000001b72d551c -[FBSSerialQueue _queue_performNextIfPossible] + 404 (FBSSerialQueue.m:216)
    44  FrontBoardServices            	0x00000001b72d5a44 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:247)
    45  CoreFoundation                	0x00000001b2083ad8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1922)
    46  CoreFoundation                	0x00000001b2083a30 __CFRunLoopDoSource0 + 80 (CFRunLoop.c:1956)
    47  CoreFoundation                	0x00000001b20831b8 __CFRunLoopDoSources0 + 184 (CFRunLoop.c:1992)
    48  CoreFoundation                	0x00000001b207e1e8 __CFRunLoopRun + 788 (CFRunLoop.c:2882)
    49  CoreFoundation                	0x00000001b207dba8 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192)
    50  GraphicsServices              	0x00000001bc1ed344 GSEventRunModal + 160 (GSEvent.c:2246)
    51  UIKitCore                     	0x00000001b61b93e4 UIApplicationMain + 1932 (UIApplication.m:4823)
    52  <game name>                    	0x0000000100f51cf4 dmEngine::RunLoop(dmEngine::RunLoopParams const*) + 40180 (engine_loop.cpp:25)
    53  <game name>                    	0x0000000100f51cb4 engine_main(int, char**) + 40116 (engine_main.cpp:126)
    54  libdyld.dylib                 	0x00000001b1f058f0 start + 4
1 Like

Thanks @AarrrBee ! Could you please create an issue on GitHub for this as well?

1 Like

Update:
It’s possible that the crash happens when a user forcibly quits the game when it’s not responding to input, and the cause of that seems similar to what’s discussed here: Crash when app comes back from sleep - #25 by britzl
There are 2 scripting errors in analytics data. The first is:

argument #1 contains one or more values which are not numbers: vmath.vector3(nan, nan, nan)

which occurs when we’re determining how to scroll the camera in response to touch drag input:

local world_diff = camera.screen_to_world(cameraId, screen) - camera.screen_to_world(cameraId, self.pressed_position)

It seems plausible that this is caused by window width/height being 0, as discussed in the other thread, and we can easily guard against that.

The other one is similar - we forward input to a cursor object from a controller (based on defold-input/controller.script) but again we convert from screen to world space before doing so.

What doesn’t make sense is why the game is receiving input at the moment it’s resuming from sleep.

I also don’t understand why this problem lasts more than a few frames when resuming.

Yes, sounds strange. Unless input events were queued when the device went to sleep and are sent when resuming from sleep-

I now guard against the vector3 nan issue be checking the return value of defold-orthographic camera.get_window_size(). There are no lua errors reported now, but the freezing remains. :confused:

Either the window size is remaining stuck at 0,0 or the camera script isn’t running.