Crash Fatal Exception: NSInternalInconsistencyException

I receive this crash report from Crashlytic on thousands of users after releasing an update. I can’t find out what is causing it.

The game has ad and the crash seems to happen during startup or after an interstitial ad is displayed.

Unity version is 2022.3.19

Stacktrace:

_userInfoForFileAndLine
NSInternalInconsistencyException - Internal inconsistency: the layer owning the focus ring is no longer associated with a UIView.

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x827cc __exceptionPreprocess
1  libobjc.A.dylib                0x172e4 objc_exception_throw
2  Foundation                     0x80f8d8 _userInfoForFileAndLine
3  UIKitCore                      0x362958 -[UIWindowScene _attachWindow:]
4  UIKitCore                      0x3625b4 -[UIWindow _commonInitDebugName:uiScene:]
5  UIKitCore                      0x3624a0 -[UIWindow _initWithFrame:debugName:windowScene:]
6  UIKitCore                      0x2ccaf0 -[UIApplicationRotationFollowingWindow _initWithFrame:debugName:windowScene:]
7  UIKitCore                      0x2cc8e4 -[UIWindow initWithWindowScene:]
8  UIKitCore                      0xd1a34c -[UIApplicationRotationFollowingWindow initWithWindowScene:]
9  AppStoreOverlays               0x5778 -[ASOOverlayWindow initWithWindowScene:]
10 AppStoreOverlays               0x302c -[ASOOverlayManager initWithWindowScene:]
11 AppStoreOverlays               0x37e0 -[UIWindowScene(AppOverlayManager) _aso_appOverlayManager]
12 StoreKit                       0x45fd8 +[SKOverlay dismissOverlayInScene:]
13 UnityFramework                 0x3e0dd88 AdPresenter.cleanUp()
14 UnityFramework                 0x3e0da64 AdPresenter.triggerAdClose()
15 UnityFramework                 0x3e815a0 FullScreenVC.viewWillDisappear(_:)
16 UnityFramework                 0x3e815e0 @objc FullScreenVC.viewWillDisappear(_:)
17 UIKitCore                      0xe4370 -[UIViewController _setViewAppearState:isAnimating:]
18 UIKitCore                      0x28f604 -[UIViewController __viewWillDisappear:]
19 UIKitCore                      0xa67268 __77-[UIPresentationController runTransitionForCurrentStateAnimated:handoffData:]_block_invoke_3
20 UIKitCore                      0x28f74c +[UIPresentationController _scheduleTransition:]
21 UIKitCore                      0xa66d18 -[UIPresentationController runTransitionForCurrentStateAnimated:handoffData:]
22 UIKitCore                      0xa65248 -[UIPresentationController _dismissWithAnimationController:interactionController:animated:handoffData:]
23 UIKitCore                      0x7ff30 +[UIView(Animation) performWithoutAnimation:]
24 UIKitCore                      0xb0e81c __73-[UIViewController _dismissViewControllerWithTransition:from:completion:]_block_invoke
25 UIKitCore                      0x7ff30 +[UIView(Animation) performWithoutAnimation:]
26 UIKitCore                      0xb0dd74 -[UIViewController _dismissViewControllerWithTransition:from:completion:]
27 UIKitCore                      0x525b84 -[UIViewController dismissViewControllerWithTransition:completion:]
28 UIKitCore                      0x525248 -[UIViewController _performCoordinatedPresentOrDismiss:animated:]
29 UIKitCore                      0x525008 -[UIViewController dismissViewControllerAnimated:completion:]
30 UIKitCore                      0x38c144 __68-[UIWindow _removeAllViewControllersFromWindowHierarchyFromDealloc:]_block_invoke
31 UIKitCore                      0x38c0ac +[UIViewController _performWithoutDeferringTransitionsAllowingAnimation:actions:]
32 UIKitCore                      0x38bdc4 -[UIWindow _removeAllViewControllersFromWindowHierarchyFromDealloc:]
33 UIKitCore                      0x2150d0 -[UIWindow setRootViewController:]
34 UnityFramework                 0x25e80c8 UnityCleanupTrampoline + 172 (UnityAppController.mm:172)
35 UIKitCore                      0x113fdcc -[UIApplication _terminateWithStatus:]
36 UIKitCore                      0x17ef88 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
37 UIKitCore                      0x95f8f4 -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:]
38 UIKitCore                      0x113b54c -[UIApplication workspaceShouldExit:withTransitionContext:]
39 FrontBoardServices             0x54f68 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2
40 FrontBoardServices             0x14c44 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
41 FrontBoardServices             0x54f08 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke
42 libdispatch.dylib              0x40d0 _dispatch_client_callout
43 libdispatch.dylib              0x7b14 _dispatch_block_invoke_direct
44 FrontBoardServices             0x16300 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
45 FrontBoardServices             0x16280 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible]
46 FrontBoardServices             0x16158 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource]
47 CoreFoundation                 0x56328 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
48 CoreFoundation                 0x562bc __CFRunLoopDoSource0
49 CoreFoundation                 0x53e24 __CFRunLoopDoSources0
50 CoreFoundation                 0x52fbc __CFRunLoopRun
51 CoreFoundation                 0x52830 CFRunLoopRunSpecific
52 GraphicsServices               0x11c4 GSEventRunModal
53 UIKitCore                      0x3d2eb0 -[UIApplication _run]
54 UIKitCore                      0x4815b4 UIApplicationMain
55 UnityFramework                 0x25ecaf0 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 96 (main.mm:96)
56 GameName                       0x412c main + 28 (main.mm:28)
57 ???                            0x1bb276ec8 (Missing)

Crashed: com.google.firebase.crashlytics.ios.exception
0  UnityFramework                 0x2931fb4 FIRCLSProcessRecordAllThreads + 392 (FIRCLSProcess.c:392)
1  UnityFramework                 0x2932398 FIRCLSProcessRecordAllThreads + 423 (FIRCLSProcess.c:423)
2  UnityFramework                 0x29292e4 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  UnityFramework                 0x292402c __FIRCLSExceptionRecord_block_invoke + 240 (FIRCLSException.mm:240)
4  libdispatch.dylib              0x40d0 _dispatch_client_callout + 20
5  libdispatch.dylib              0x13750 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  UnityFramework                 0x2922f88 FIRCLSExceptionRecord + 242 (FIRCLSException.mm:242)
7  UnityFramework                 0x2923ae4 FIRCLSExceptionRecordNSException + 126 (FIRCLSException.mm:126)
8  UnityFramework                 0x2922b90 FIRCLSTerminateHandler() + 407 (FIRCLSException.mm:407)
9  libc++abi.dylib                0x1287c std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x12820 std::terminate() + 108
11 libobjc.A.dylib                0x3f948 objc_terminate + 16
12 libdispatch.dylib              0x40e4 _dispatch_client_callout + 40
13 libdispatch.dylib              0x7b14 _dispatch_block_invoke_direct + 284
14 FrontBoardServices             0x16300 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52
15 FrontBoardServices             0x16280 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240
16 FrontBoardServices             0x16158 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28
17 CoreFoundation                 0x56328 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
18 CoreFoundation                 0x562bc __CFRunLoopDoSource0 + 176
19 CoreFoundation                 0x53e24 __CFRunLoopDoSources0 + 344
20 CoreFoundation                 0x52fbc __CFRunLoopRun + 840
21 CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
22 GraphicsServices               0x11c4 GSEventRunModal + 164
23 UIKitCore                      0x3d2eb0 -[UIApplication _run] + 816
24 UIKitCore                      0x4815b4 UIApplicationMain + 340
25 UnityFramework                 0x25ecaf0 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 96 (main.mm:96)
26 GameName                       0x412c main + 28 (main.mm:28)
27 ???                            0x1bb276ec8 (Missing)

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  Foundation                     0xb7500 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0xb7350 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9  UIKitCore                      0x3e6358 -[UIEventFetcher threadMain] + 420
10 Foundation                     0xc86c8 __NSThread__start__ + 724
11 libsystem_pthread.dylib        0x637c _pthread_start + 136
12 libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9090679934

JavaScriptCore libpas scavenger
0  libsystem_kernel.dylib         0x6f90 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x3a50 _pthread_cond_wait + 1204
2  JavaScriptCore                 0x15a6ca4 scavenger_thread_main + 1512
3  libsystem_pthread.dylib        0x637c _pthread_start + 136
4  libsystem_pthread.dylib        0x1494 thread_start + 8

caulk::deferred_logger
0  libsystem_kernel.dylib         0x1604 semaphore_wait_trap + 8
1  caulk                          0x4a0c caulk::semaphore::timed_wait(double) + 220
2  caulk                          0x48c4 caulk::concurrent::details::worker_thread::run() + 36
3  caulk                          0x480c void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*>>>(void*) + 96
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

caulk.messenger.shared:high
0  libsystem_kernel.dylib         0x1604 semaphore_wait_trap + 8
1  caulk                          0x4a0c caulk::semaphore::timed_wait(double) + 220
2  caulk                          0x48c4 caulk::concurrent::details::worker_thread::run() + 36
3  caulk                          0x480c void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*>>>(void*) + 96
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.CoreMotion.MotionThread
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  CoreFoundation                 0xbdcec CFRunLoopRun + 64
8  CoreMotion                     0x10084 (Missing UUID ad76b51c2c19371888c6e6a9d73d5868)
9  libsystem_pthread.dylib        0x637c _pthread_start + 136
10 libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  CFNetwork                      0xfdee0 +[__CFN_CoreSchedulingSetRunnable _run:] + 416
8  Foundation                     0xc86c8 __NSThread__start__ + 724
9  libsystem_pthread.dylib        0x637c _pthread_start + 136
10 libsystem_pthread.dylib        0x1494 thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  UnityFramework                 0x292b9e8 FIRCLSMachExceptionServer + 192 (FIRCLSMachException.c:192)
5  libsystem_pthread.dylib        0x637c _pthread_start + 136
6  libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

com.apple.root.user-initiated-qos
0  libsystem_kernel.dylib         0x7ad0 __ulock_wait + 8
1  libdispatch.dylib              0x4ac0 _dlock_wait + 56
2  libdispatch.dylib              0x4874 _dispatch_thread_event_wait_slow + 56
3  libdispatch.dylib              0x13a3c __DISPATCH_WAIT_FOR_QUEUE__ + 368
4  libdispatch.dylib              0x135e8 _dispatch_sync_f_slow + 148
5  AppLovinSDK                    0x108624 -[ALDataCollector collectBatteryInfoIfNeeded:] + 220
6  AppLovinSDK                    0x106c74 -[ALDataCollector collectDeviceInfo] + 772
7  AppLovinSDK                    0x10512c -[ALDataCollector requestParametersWithAdInfo:nested:] + 84
8  AppLovinSDK                    0x69048 -[ALEventService queryParametersForEvent:] + 208
9  AppLovinSDK                    0x68b38 __52-[ALEventService trackEvent:parameters:HTTPHeaders:]_block_invoke + 72
10 AppLovinSDK                    0x8026c -[ALBlockTask run] + 36
11 AppLovinSDK                    0x13fa28 -[ALTask main] + 348
12 libdispatch.dylib              0x2370 _dispatch_call_block_and_release + 32
13 libdispatch.dylib              0x40d0 _dispatch_client_callout + 20
14 libdispatch.dylib              0x15f60 _dispatch_root_queue_drain + 860
15 libdispatch.dylib              0x16590 _dispatch_worker_thread2 + 156
16 libsystem_pthread.dylib        0x4c40 _pthread_wqthread + 228
17 libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9090679934

MTGAsyncSocket-CFStream
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  Foundation                     0xb7500 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  UnityFramework                 0x30f25f8 +[MTGAsyncSocket cfstreamThread:] + 52684
9  Foundation                     0xc86c8 __NSThread__start__ + 724
10 libsystem_pthread.dylib        0x637c _pthread_start + 136
11 libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.CFSocket.private
0  libsystem_kernel.dylib         0x9234 select$DARWIN_EXTSN + 8
1  libsystem_kernel.dylib         0x9234 __select + 8
2  CoreFoundation                 0xbb95c __CFSocketManager + 704
3  libsystem_pthread.dylib        0x637c _pthread_start + 136
4  libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

AudioSession - RootQueue
0  libsystem_kernel.dylib         0x161c semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x46e8 _dispatch_sema4_timedwait + 64
2  libdispatch.dylib              0x4ce8 _dispatch_semaphore_wait_slow + 76
3  libdispatch.dylib              0x15b60 _dispatch_worker_thread + 324
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Hello there,

I tried looking to see if we have any similar crashes reported already but sadly nothing was found.

If possible please report this issue via the Unity Bug Reporter and provide us with the project in the report so that it could be looked at by the developers. As right now there really is nothing to go on besides seeing the Stack Trace and seeing where it’s crashing and not why it’s crashing.

You can report the Bug by going into your Project then in the Toolbar press “Help → Report a Bug…”

1 Like

Yeah this sounds like a bug in ads code. if you check the callstack it comes from [UIApplication _terminateWithStatus:] which is a shutdown sequence, and then it goes to

10 AppStoreOverlays               0x302c -[ASOOverlayManager initWithWindowScene:]
11 AppStoreOverlays               0x37e0 -[UIWindowScene(AppOverlayManager) _aso_appOverlayManager]
12 StoreKit                       0x45fd8 +[SKOverlay dismissOverlayInScene:]
13 UnityFramework                 0x3e0dd88 AdPresenter.cleanUp()
14 UnityFramework                 0x3e0da64 AdPresenter.triggerAdClose()
15 UnityFramework                 0x3e815a0 FullScreenVC.viewWillDisappear(_:)

so it seems that something “goes wrong” internally and it start to recreate some internal state, leading to creating windows/scenes and so on (and this probably happens at a bad time already)

As @GediminasR suggested create a jira ticket, include callstack and say that ads team should look into it

2 Likes

Hi @cdr9042

We’re experiencing the exact same issue. Have you found a solution to this crash?

Not sure if it’s because of my fix but the crash rate has gone down. I updated Ad SDK, and in the code that handle Inter ad closed event, I have a line:
Time.timeScale = 1;
I added code to enqueue it to Unity Main Thread

void OnInterstitialAdClosed(...){
#if UNITY_IOS
UnityMainThreadDispatcher. Instance().Enqueue(()
{
Time.timeScale = 1;
});
#endif
}

As I understand - linked post iOS Crash Fatal Exception: NSInternalInconsistencyException - #6 by khushalkhan

Does the problem persist?
What ad display libraries do you use?
mediation?

I’m not sure but it might’ve been AppLovin MAX, it used mediation