Crash apparently caused by auto-layout UI changes on background thread

I've been getting occasional crash reports that look similar to this:


Fatal Exception: NSInternalInconsistencyException
Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x19dcd0a48 __exceptionPreprocess
1  libobjc.A.dylib                0x19d9f7fa4 objc_exception_throw
2  Foundation                     0x19e1a6f08 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints]
3  Foundation                     0x19dfa803c -[NSISEngine withBehaviors:performModifications:]
4  UIKitCore                      0x1a20ff8e8 -[UIView(UIConstraintBasedLayout) _resetLayoutEngineHostConstraints]
5  UIKitCore                      0x1a21d9314 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
6  QuartzCore                     0x1a473c7dc -[CALayer layoutSublayers]
7  QuartzCore                     0x1a4742958 CA::Layer::layout_if_needed(CA::Transaction*)
8  QuartzCore                     0x1a474d578 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
9  QuartzCore                     0x1a4695f1c CA::Context::commit_transaction(CA::Transaction*, double)
10 QuartzCore                     0x1a46bfc08 CA::Transaction::commit()
11 QuartzCore                     0x1a46c0b8c CA::Transaction::release_thread(void*)
12 libsystem_pthread.dylib        0x19d9eefb0 _pthread_tsd_cleanup
13 libsystem_pthread.dylib        0x19d9ebde8 _pthread_exit
14 libsystem_pthread.dylib        0x19d9ece7c _pthread_wqthread_legacy_worker_wrap
15 libsystem_pthread.dylib        0x19d9ecc18 _pthread_wqthread
16 libsystem_pthread.dylib        0x19d9ef760 start_wqthread

This is not being invoked by my code (at least directly). I've been running the app in the debugger with the Main Thread Checker enabled and have yet to catch whatever is causing this.


I've found multiple reports from others who have been experiencing similar issues, most commonly on iOS 13. (My app only supports 13 and later.) I have yet to see any solid explanation. @Eskimo - is it possible that iOS is invoking something that results in a UI state change which is called from a background thread?


Thanks,


-S

Post not yet marked as solved Up vote post of ssokol Down vote post of ssokol
7.4k views

Replies

Same here..

Exception Codes: 0x0000000000000001, 0x00000001aba87c34
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [4363]

Triggered by Thread:  12

Last Exception Backtrace:
0   CoreFoundation                	0x1a3bbeb28 __exceptionPreprocess + 164 (NSException.m:249)
1   libobjc.A.dylib               	0x19ba36f78 objc_exception_throw + 60 (objc-exception.mm:356)
2   CoreAutoLayout                	0x1c4b5765c _AssertAutoLayoutOnAllowedThreadsOnly + 328 (NSISEngine.m:0)
3   CoreAutoLayout                	0x1c4b5da70 -[NSISEngine _optimizeWithoutRebuilding] + 72 (NSISEngine.m:1716)
4   CoreAutoLayout                	0x1c4b5d784 -[NSISEngine optimize] + 96 (NSISEngine.m:1690)
5   CoreAutoLayout                	0x1c4b5d510 -[NSISEngine performPendingChangeNotifications] + 104 (NSISEngine.m:684)
6   UIKitCore                     	0x1a5d813c8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2248 (UIView.m:20093)
7   QuartzCore                    	0x1a51abe30 CA::Layer::layout_if_needed(CA::Transaction*) + 504 (CALayer.mm:10816)
8   QuartzCore                    	0x1a51ab9b4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 (CALayer.mm:2598)
9   QuartzCore                    	0x1a51b1bb4 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 (CAContextInternal.mm:2760)
10  QuartzCore                    	0x1a51ab1bc CA::Transaction::commit() + 648 (CATransactionInternal.mm:432)
11  QuartzCore                    	0x1a533fee4 CA::Transaction::release_thread(void*) + 228 (CATransactionInternal.mm:636)
12  libsystem_pthread.dylib       	0x1ffabdb8c _pthread_tsd_cleanup + 620 (pthread_tsd.c:416)
13  libsystem_pthread.dylib       	0x1ffab7f84 _pthread_exit + 84 (pthread.c:1766)
14  libsystem_pthread.dylib       	0x1ffab9854 _pthread_wqthread_exit + 64 (pthread.c:2625)
15  libsystem_pthread.dylib       	0x1ffab4fa8 _pthread_wqthread + 424 (pthread.c:2659)
16  libsystem_pthread.dylib       	0x1ffab4fc0 start_wqthread + 8 (:-1)

...

hread 12 Crashed:
0   libsystem_c.dylib             	0x00000001aba87c34 __abort + 168 (abort.c:171)
1   libsystem_c.dylib             	0x00000001aba87b8c abort + 192 (abort.c:126)
2   libc++abi.dylib               	0x00000001ff9d8ccc abort_message + 132 (abort_message.cpp:78)
3   libc++abi.dylib               	0x00000001ff9c8e84 demangling_terminate_handler() + 348 (cxa_default_handlers.cpp:77)
4   libobjc.A.dylib               	0x000000019ba3a0bc _objc_terminate() + 144 (objc-exception.mm:496)
5   libc++abi.dylib               	0x00000001ff9d8090 std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:59)
6   libc++abi.dylib               	0x00000001ff9db2e4 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88 (cxa_exception.cpp:152)
7   libc++abi.dylib               	0x00000001ff9db228 __cxa_throw + 308 (cxa_exception.cpp:283)
8   libobjc.A.dylib               	0x000000019ba370e0 objc_exception_throw + 420 (objc-exception.mm:385)
9   CoreAutoLayout                	0x00000001c4b5765c _AssertAutoLayoutOnAllowedThreadsOnly + 328 (NSISEngine.m:0)
10  CoreAutoLayout                	0x00000001c4b5da70 -[NSISEngine _optimizeWithoutRebuilding] + 72 (NSISEngine.m:1716)
11  CoreAutoLayout                	0x00000001c4b5d784 -[NSISEngine optimize] + 96 (NSISEngine.m:1690)
12  CoreAutoLayout                	0x00000001c4b5d510 -[NSISEngine performPendingChangeNotifications] + 104 (NSISEngine.m:684)
13  UIKitCore                     	0x00000001a5d813c8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2248 (UIView.m:20093)
14  QuartzCore                    	0x00000001a51abe30 CA::Layer::layout_if_needed(CA::Transaction*) + 504 (CALayer.mm:10816)
15  QuartzCore                    	0x00000001a51ab9b4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 (CALayer.mm:2598)
16  QuartzCore                    	0x00000001a51b1bb4 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 (CAContextInternal.mm:2760)
17  QuartzCore                    	0x00000001a51ab1bc CA::Transaction::commit() + 648 (CATransactionInternal.mm:432)
18  QuartzCore                    	0x00000001a533fee4 CA::Transaction::release_thread(void*) + 228 (CATransactionInternal.mm:636)
19  libsystem_pthread.dylib       	0x00000001ffabdb8c _pthread_tsd_cleanup + 620 (pthread_tsd.c:416)
20  libsystem_pthread.dylib       	0x00000001ffab7f84 _pthread_exit + 84 (pthread.c:1766)
21  libsystem_pthread.dylib       	0x00000001ffab9854 _pthread_wqthread_exit + 64 (pthread.c:2625)
22  libsystem_pthread.dylib       	0x00000001ffab4fa8 _pthread_wqthread + 424 (pthread.c:2659)
23  libsystem_pthread.dylib       	0x00000001ffab4fc0 start_wqthread + 8 (:-1)