iOS App crashes on rotation while in the background

I'm developing an iOS app that can receive silent remote notifications, so that it's occasionally active in the background.


I've received several crash logs that seemingly indicate the app crashes when the device is rotated while the app is in the background. It's near impossible for me to reproduce, and it does not occur while responding to a silent notification. From other logging, it appears the app is quiescent.


Any idea why a background app would react to device rotation?


There are similar queries about this type of thing on stackoverflow https://stackoverflow.com/questions/59287580/ios-crash-with-spritekit-when-app-is-in-background and https://stackoverflow.com/questions/59863771/ios-13-crash-with-uibuttonbarstackview-possibly-on-rotation.


Relevant crash data is as follows:


Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104cb8f24
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [11726]
Triggered by Thread:  0


Thread 0 name:
Thread 0 Crashed:
0   [MyAppName]                   0x0000000104cb8f24 specialized [MyAppsViewController].collectionView(_:layout:sizeForItemAt:) + 1512 (<compiler-generated>:0)
1   [MyAppName]                   0x0000000104cb6c1c @objc [MyAppsViewController].collectionView(_:layout:sizeForItemAt:) + 164 (<compiler-generated>:0)
2   UIKitCore                     0x00000001941c9030 -[UICollectionViewFlowLayout _getSizingInfosWithExistingSizingDictionary:] + 2972 (UICollectionViewFlowLayout.m:1443)
3   UIKitCore                     0x00000001941ca5b0 -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 260 (UICollectionViewFlowLayout.m:1675)
4   UIKitCore                     0x00000001941c4238 -[UICollectionViewFlowLayout prepareLayout] + 220 (UICollectionViewFlowLayout.m:376)
5   UIKitCore                     0x00000001941bd7bc -[UICollectionViewData _prepareToLoadData] + 228 (UICollectionViewData.mm:334)
6   UIKitCore                     0x00000001941be050 -[UICollectionViewData validateLayoutInRect:] + 104 (UICollectionViewData.mm:400)
7   UIKitCore                     0x000000019418f434 -[UICollectionView layoutSubviews] + 224 (UICollectionView.m:3949)
8   UIKitCore                     0x0000000194db73d0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2140 (UIView.m:17028)
9   QuartzCore                     0x000000019731a7dc -[CALayer layoutSublayers] + 284 (CALayer.mm:9627)
10  QuartzCore                     0x0000000197320958 CA::Layer::layout_if_needed(CA::Transaction*) + 480 (CALayer.mm:9501)
11  UIKitCore                     0x0000000194da3684 -[UIView(Hierarchy) layoutBelowIfNeeded] + 536 (UIView.m:12017)
12  UIKitCore                     0x0000000194279358 -[UINavigationController _layoutViewController:] + 1188 (UINavigationController.m:6432)
13  UIKitCore                     0x0000000194273210 -[UINavigationController _layoutTopViewControllerLookForNested:] + 604 (UINavigationController.m:4871)
14  UIKitCore                     0x0000000194269ab8 __105-[UINavigationController _repositionPaletteWithNavigationBarHidden:duration:shouldUpdateNavi... + 716 (UINavigationController.m:2677)
15  UIKitCore                     0x00000001942697b4 -[UINavigationController _repositionPaletteWithNavigationBarHidden:duration:shouldUpdateNavigatio... + 264 (UINavigationController.m:2694)
16  UIKitCore                     0x00000001942723d8 -[UINavigationController _updateBarsForCurrentInterfaceOrientationAndForceBarLayout:] + 176 (UINavigationController.m:4645)
17  UIKitCore                     0x0000000194332600 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 264 (UIViewControllerTransitioning.m:1140)
18  UIKitCore                     0x000000019432efb0 -[_UIViewControllerTransitionContext __runAlongsideAnimations] + 256 (UIViewControllerTransitioning.m:411)
19  UIKitCore                     0x0000000194dab530 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animat... + 564 (UIView.m:14134)
20  UIKitCore                     0x0000000194dabb10 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 108 (UIView.m:14193)
21  UIKitCore                     0x0000000194344f60 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke_2 + 308 (_UIWindowAnimationController.m:187)
22  UIKitCore                     0x0000000194daf484 +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:forScene:] + 204 (UIView.m:15076)
23  UIKitCore                     0x0000000194344ccc __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 164 (_UIWindowAnimationController.m:176)
24  UIKitCore                     0x0000000194344ba4 -[_UIWindowRotationAnimationController animateTransition:] + 492 (_UIWindowAnimationController.m:227)
25  UIKitCore                     0x000000019495fb1c -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 580 (UIWindow.m:3539)
26  UIKitCore                     0x000000019496211c -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 1436 (UIWindow.m:4071)
27  UIKitCore                     0x0000000194962634 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 412 (UIWindow.m:4105)
28  UIKitCore                     0x00000001949619e8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 128 (UIWindow.m:3947)
29  UIKitCore                     0x0000000194960954 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 124 (UIWindow.m:3657)
30  UIKitCore                     0x000000019496085c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 436 (UIWindow.m:3703)
31  CoreFoundation                 0x000000019080a288 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:787)
32  CoreFoundation                 0x000000019080a2d0 ___CFXRegistrationPost1_block_invoke + 64 (CFNotificationCenter.c:175)
33  CoreFoundation                 0x0000000190809630 _CFXRegistrationPost1 + 368 (CFNotificationCenter.c:198)
34  CoreFoundation                 0x00000001908092e8 ___CFXNotificationPost_block_invoke + 104 (CFNotificationCenter.c:1371)
35  CoreFoundation                 0x000000019078559c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1416 (CFXNotificationRegistrarOld.m:168)
36  CoreFoundation                 0x0000000190808c38 _CFXNotificationPost + 1244 (CFNotificationCenter.c:1359)
37  Foundation                     0x0000000190b65138 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60 (NSNotification.m:576)
38  UIKitCore                     0x000000019459f128 -[UIDevice setOrientation:animated:] + 252 (UIDevice.m:799)
39  UIKitCore                     0x00000001940ed96c __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransiti... + 1568 (_UISceneLifecycleMultiplexer.m:557)
40  UIKitCore                     0x0000000194582b70 _UIScenePerformActionsWithLifecycleActionMask + 100 (_UISceneLifecycleState.m:109)
41  UIKitCore                     0x00000001940ed2b0 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransiti... + 196 (_UISceneLifecycleMultiplexer.m:501)
42  UIKitCore                     0x00000001940ecd08 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296 (_UISceneLifecycleMultiplexer.m:450)
43  UIKitCore                     0x00000001940ed0dc -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionSto... + 736 (_UISceneLifecycleMultiplexer.m:500)
44  UIKitCore                     0x00000001940ec998 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 336 (_UISceneLifecycleMultiplexer.m:406)
45  UIKitCore                     0x00000001940f0e84 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsFo... + 188 (_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction.m:102)
46  UIKitCore                     0x00000001944b43e0 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 824 (BSAnimationSettings+UIKit.m:50)
47  UIKitCore                     0x000000019459c15c _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 244 (_UISceneSettingsDiffAction.m:43)
48  UIKitCore                     0x00000001940f0bbc __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsFo... + 136 (_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction.m:87)
49  UIKitCore                     0x000000019459c058 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 100 (_UISceneSettingsDiffAction.m:35)
50  UIKitCore                     0x00000001940f0a28 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUISc... + 376 (_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction.m:85)
51  UIKitCore                     0x0000000193f62880 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 636 (UIScene.m:1338)
52  UIKitCore                     0x0000000193f613e8 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248 (UIScene.m:1071)
53  UIKitCore                     0x0000000193f625b8 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220 (UIScene.m:1315)
54  UIKitCore                     0x00000001944d5248 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464 (UIApplicationSceneClientAgent.m:80)
55  FrontBoardServices             0x00000001959cf248 -[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:] + 544 (FBSSceneImpl.m:551)
56  FrontBoardServices             0x00000001959f3d28 __88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]_bloc... + 120 (FBSWorkspaceScenesClient.m:356)
57  FrontBoardServices             0x00000001959d8f04 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 232 (FBSWorkspace.m:357)
58  FrontBoardServices             0x00000001959f3c5c __88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]_bloc... + 184 (FBSWorkspaceScenesClient.m:355)
59  libdispatch.dylib             0x000000019057b184 _dispatch_client_callout + 16 (object.m:495)
60  libdispatch.dylib             0x0000000190523fd8 _dispatch_block_invoke_direct$VARIANT$mp + 224 (queue.c:466)
61  FrontBoardServices             0x0000000195a18418 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40 (FBSSerialQueue.m:173)
62  FrontBoardServices             0x0000000195a180e4 -[FBSSerialQueue _queue_performNextIfPossible] + 404 (FBSSerialQueue.m:216)
63  FrontBoardServices             0x0000000195a1860c -[FBSSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:247)
64  CoreFoundation                 0x000000019082ca00 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1922)
65  CoreFoundation                 0x000000019082c958 __CFRunLoopDoSource0 + 80 (CFRunLoop.c:1956)
66  CoreFoundation                 0x000000019082c0f0 __CFRunLoopDoSources0 + 180 (CFRunLoop.c:1992)
67  CoreFoundation                 0x000000019082723c __CFRunLoopRun + 1080 (CFRunLoop.c:2882)
68  CoreFoundation                 0x0000000190826adc CFRunLoopRunSpecific + 464 (CFRunLoop.c:3192)
69  GraphicsServices               0x000000019a7ac328 GSEventRunModal + 104 (GSEvent.c:2246)
70  UIKitCore                     0x0000000194921ae0 UIApplicationMain + 1936 (UIApplication.m:4773)
71  [MyAppName]                   0x0000000104bc534c main + 68 ([MyAppsUIControl].swift:18)
72  libdyld.dylib                 0x00000001906b0360 start + 4
iOS App crashes on rotation while in the background
 
 
Q