UIKitCore Crash When Entering Foreground

Hey friends, I have a crash that's been plaguing me for some time now that I've made no progress on, so I'm throwing a hail-mary here.


General information:

- This stack trace is taken from Fabric/Firebase.

- It is only happening on iOS13, across all versions of iOS 13 that appear active for our users, from 13.1.3 up to and including 13.3.0

- It's happening to all live versions of our application that support iOS 13 (it is affecting versions that were released before iOS 13 came out, so it's not something we introduced recently)

- It has impacted around 10k of our users in the last month and is by far the most prevalent crash we're experiencing.

- The app is a messaging app

- Though the stack trace includes a lot of scene delegate frames, our app has not implemented a UISceneDelegate, everything still goes through our UIAppDelegate implementation only.


Debugging Information:

- I've been unable to reproduce the crash, either with the live AppStore build or running locally through Xcode on device or simulator

- I've set symbolic breakpoint on -[UIView(Internal) _addSubview:positioned:relativeTo:], which is called a ton, but haven't seen a stack trace with similar elements to the stack trace of this crash when resuming the app from background.

- Since the symbolic breakpoint is set on an internal function, I'm unaware of any logging I could include to gain additional information

- The last (or nearly last) entry in our crash logging is a record of applicationDidEnterBackground: being called, so I initially assumed the app was simply crashing in the background, but then noticed that each of the stack traces include -[UIApplication _sendWillEnterForegroundCallbacks], so I'm led to believe that this is happening when the user resumes the app from a backgrounded state.


I generally understand what the crash code means and that objc_msgSend means a message is being sent to a deallocated object, but without being able to reproduce I don't know of any course of action I can take to move towards resolving this. Any clues or pointers or information or ideas you might have would be greatly appreciated. Cheers.


Stack Trace:

Crashed: com.apple.main-thread

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010


Crashed: com.apple.main-thread

0 libobjc.A.dylib 0x18325cfb0 objc_msgSend + 16

1 UIKitCore 0x187ae2ba0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 540

2 UIKitCore 0x18741c61c -[UIInputWindowController changeToInputViewSet:] + 1656

3 UIKitCore 0x18741d0d4 __43-[UIInputWindowController setInputViewSet:]_block_invoke + 64

4 UIKitCore 0x187adbfc0 +[UIView(Animation) performWithoutAnimation:] + 104

5 UIKitCore 0x18741cdd8 -[UIInputWindowController setInputViewSet:] + 732

6 UIKitCore 0x187417358 -[UIInputWindowController performOperations:withAnimationStyle:] + 60

7 UIKitCore 0x1871325c4 -[UIInputResponderController setKeyWindowSceneInputViews:animationStyle:] + 2184

8 UIKitCore 0x187131d14 -[UIInputResponderController setInputViews:animationStyle:] + 216

9 UIKitCore 0x1871343b4 -[UIInputResponderController forceOrderOutAutomaticExceptAccessoryView] + 484

10 UIKitCore 0x1879ff32c -[UIKeyboardAutomatic willResume:] + 732

11 Foundation 0x18391306c __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_2 + 28

12 CoreFoundation 0x1834a099c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 28

13 CoreFoundation 0x1834a09ec ___CFXRegistrationPost1_block_invoke + 68

14 CoreFoundation 0x18349fce4 _CFXRegistrationPost1 + 396

15 CoreFoundation 0x18349f97c ___CFXNotificationPost_block_invoke + 108

16 CoreFoundation 0x183418910 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1424

17 CoreFoundation 0x18349f2ac _CFXNotificationPost + 1268

18 Foundation 0x183801bfc -[NSNotificationCenter postNotificationName:object:userInfo:] + 64

19 UIKitCore 0x18764d06c -[UIApplication _sendWillEnterForegroundCallbacks] + 284

20 UIKitCore 0x186dce420 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 1780

21 UIKitCore 0x18727e9f8 _UIScenePerformActionsWithLifecycleActionMask + 112

22 UIKitCore 0x186dcdc90 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 212

23 UIKitCore 0x186dcd6c0 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 304

24 UIKitCore 0x186dcdaac -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 752

25 UIKitCore 0x186dcd330 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 340

26 UIKitCore 0x186dd1ab0 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 196

27 UIKitCore 0x18729887c ___UISceneSettingsDiffActionPerformChangesWithTransitionContext_block_invoke + 28

28 UIKitCore 0x1871aac9c +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 868

29 UIKitCore 0x187298834 _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 260

30 UIKitCore 0x186dd17c8 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 152

31 UIKitCore 0x18729871c _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 108

32 UIKitCore 0x186dd1624 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 392

33 UIKitCore 0x186c399a0 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 640

34 UIKitCore 0x186c38464 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 256

35 UIKitCore 0x186c396d0 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 236

36 UIKitCore 0x187632c10 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 564

37 UIKitCore 0x1871ccb9c -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 376

38 FrontBoardServices 0x18872ae10 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 452

39 FrontBoardServices 0x188751aa0 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.168 + 116

40 FrontBoardServices 0x188735ef4 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240

41 FrontBoardServices 0x188751734 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 344

42 libdispatch.dylib 0x1831edfd8 _dispatch_client_callout + 20

43 libdispatch.dylib 0x1831f0d1c _dispatch_block_invoke_direct + 264

44 FrontBoardServices 0x188778254 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48

45 FrontBoardServices 0x188777f00 -[FBSSerialQueue _queue_performNextIfPossible] + 432

46 FrontBoardServices 0x18877846c -[FBSSerialQueue _performNextFromRunLoopSource] + 32

47 CoreFoundation 0x1834c4108 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28

48 CoreFoundation 0x1834c405c __CFRunLoopDoSource0 + 84

49 CoreFoundation 0x1834c37c8 __CFRunLoopDoSources0 + 184

50 CoreFoundation 0x1834be694 __CFRunLoopRun + 1068

51 CoreFoundation 0x1834bdf40 CFRunLoopRunSpecific + 480

52 GraphicsServices 0x18d73b534 GSEventRunModal + 108

53 UIKitCore 0x187636a60 UIApplicationMain + 1940

54 Remind101 0x10232aa8c main + 16 (main.m:16)

55 libdyld.dylib 0x18333ce18 start + 4


(16 other threads appear dormant)

We've been seeing this too - it's the number one crash in our app currently. I created a thread about it while back here:

https://forums.developer.apple.com/message/392520#392520


There are also threads about this issue that are very likely either related or the same problem, here:

https://forums.developer.apple.com/message/386327#386327

https://forums.developer.apple.com/message/401926#401926


And there are probably more... I created a DTS request about it a while ago, Apple just refunded the DTS credit for it and pasted some generic copy about using Xcode bug tools to diagnose the (so far locally unreproducable) issue.


I really wish someone would look into it because like I said it's the #1 crash in our app, it feels like an iOS bug, and any hints on how it could be worked-around would be super-helpful...

Just to add, our experience matches almost exactly the points you describe, the points which coincide:

- It is only happening on iOS13, across all versions of iOS 13 that appear active for our users, from 13.2.0 and up

- It's happening to all live versions of our application that support iOS 13 (it is affecting versions that were released before iOS 13 came out, so it's not something we introduced recently)

- Though the stack trace includes a lot of scene delegate frames, our app has not implemented a UISceneDelegate, everything still goes through our UIAppDelegate implementation only

Have filed radar FB7562386 in case it also catched someone's eye on a tech team.

We have the same problems in our project.

I guess it's because we used 'inputAccessoryView' wrong way.

I used it by method override. In that method, I checked some cconditions for returning inputAccessoryView.

Depends on the condition, it returned inputAccessoryView or nil.


Another VC that uses inputAccessoryView in our app is not making the crash.


If you want to reproduce that crash, just tap textview or textfield that shown with inputAccessoryView, and then change iPhone status to multi-tasking mode and slide up your app for terminating.


I could reproduce that crashes on my phone.


We'll change the usage of this way to fix the crash.

I hope this will be helpful.

UIKitCore Crash When Entering Foreground
 
 
Q