Modifications to the layout engine must not be performed from a background thread on iOS 17 and above

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.

I have been experiencing frequent crashes on iOS 17 and above recently, and I'm having trouble pinpointing the source of the crashes. The crash logs provide no information about the specific location of the crashes. Is there any workaround or solution to identify and resolve this issue?

Please find attached the crash logs below

Replies

I have a similar crash that I'm looking into when using the iPadAir (5th generation) (17.0.1) simulator. I am thinking it is either to do with a keyboard pop-up or my updating of @State variables that are used to refresh a view (which is in the background of a .sheet)

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.' *** First throw call stack: ( 0 CoreFoundation 0x000000018048d8a8 __exceptionPreprocess + 172 1 libobjc.A.dylib 0x000000018008409c objc_exception_throw + 56 2 CoreAutoLayout 0x00000001ca3ad284 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] + 0 3 CoreAutoLayout 0x00000001ca3ad664 -[NSISEngine withBehaviors:performModifications:] + 32 4 UIKitCore 0x00000001857bbffc -[UIView _postMovedFromSuperview:] + 448 5 UIKitCore 0x00000001857c8c10 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 2192 6 UIKitCore 0x0000000184d8e1e4 -[_UITextLayoutCanvasView textViewportLayoutController:configureRenderingSurfaceForTextLayoutFragment:] + 496 7 UIFoundation 0x0000000184674d90 __48-[NSTextViewportLayoutController layoutViewport]_block_invoke_4 + 140 8 UIFoundation 0x000000018461708c __80-[NSTextLayoutManager enumerateViewportElementsFromLocation:options:usingBlock:]_block_invoke + 36 9 UIFoundation 0x000000018461260c __83-[NSTextLayoutManager enumerateTextLayoutFragmentsFromLocation:options:usingBlock:]_block_invoke_3 + 624 10 CoreFoundation 0x00000001803f245c NSARRAY_IS_CALLING_OUT_TO_A_BLOCK + 16 11 CoreFoundation 0x00000001804d537c -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] + 88 12 UIFoundation 0x0000000184612258 __83-[NSTextLayoutManager enumerateTextLayoutFragmentsFromLocation:options:usingBlock:]_block_invoke + 1400 13 UIFoundation 0x0000000184611bf0 -[NSTextLayoutManager enumerateTextLayoutFragmentsFromLocation:options:usingBlock:] + 952 14 UIFoundation 0x000000018461705c -[NSTextLayoutManager enumerateViewportElementsFromLocation:options:usingBlock:] + 72 15 UIFoundation 0x0000000184674840 -[NSTextViewportLayoutController layoutViewport] + 1340 16 UIKitCore 0x00000001857c2cf4 +[UIView(Animation) performWithoutAnimation:] + 68 17 UIKitCore 0x0000000184d8de54 -[_UITextLayoutCanvasView _performViewportLayout] + 112 18 UIKitCore 0x00000001857cdb1c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1492 19 QuartzCore 0x0000000189f6fdd4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 440 20 QuartzCore 0x0000000189f7ab30 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 124 21 QuartzCore 0x0000000189e963bc _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 460 22 QuartzCore 0x0000000189ec5bf0 _ZN2CA11Transaction6commitEv + 652 23 QuartzCore 0x0000000189ec6670 _ZN2CA11Transaction14release_threadEPv + 228 24 libsystem_pthread.dylib 0x0000000100dd1100 _pthread_tsd_cleanup + 616 25 libsystem_pthread.dylib 0x0000000100dd3b9c _pthread_exit + 80 26 libsystem_pthread.dylib 0x0000000100dd0dfc pthread_exit + 0 27 libsystem_pthread.dylib 0x0000000100dcf9ac _pthread_wqthread + 420 28 libsystem_pthread.dylib 0x0000000100dce6e4 start_wqthread + 8 ) libc++abi: terminating due to uncaught exception of type NSException

I had the same problem, did you solve it?