Getting NSInternalInconsistencyException crash after Xcode 12, iOS 14 Upgrade

After upgrading my build environment to Xcode 12 and iOS 14 my application has begun crashing with the following error:

Code Block
2020-09-22 13:49:14.896138-0500 FlightBox PFD[3347:2884020] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
 Stack:(
0   CoreAutoLayout                      0x00007fff58010c53 _AssertAutoLayoutOnAllowedThreadsOnly + 190
1   CoreAutoLayout                      0x00007fff58010fcd -[NSISEngine withBehaviors:performModifications:] + 25
2   UIKitCore                           0x00007fff24ab9bdc -[UIView(UIConstraintBasedLayout) _resetLayoutEngineHostConstraints] + 70
3   UIKitCore                           0x00007fff24bbd92f -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2715
4   QuartzCore                          0x00007fff27a3dd87 -[CALayer layoutSublayers] + 258
5   QuartzCore                          0x00007fff27a44239 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
6   QuartzCore                          0x00007fff27a4ff91 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
7   QuartzCore                          0x00007fff27990078 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
8   QuartzCore                          0x00007fff279c6e13 _ZN2CA11Transaction6commitEv + 783
9   QuartzCore                          0x00007fff279c7616 _ZN2CA11Transaction14release_threadEPv + 210
10  libsystem_pthread.dylib             0x00007fff5dcda054 _pthread_tsd_cleanup + 551
11  libsystem_pthread.dylib             0x00007fff5dcdc512 _pthread_exit + 70
12  libsystem_pthread.dylib             0x00007fff5dcd9ddd _pthread_wqthread_exit + 77
13  libsystem_pthread.dylib             0x00007fff5dcd8afc _pthread_wqthread + 481
14  libsystem_pthread.dylib             0x00007fff5dcd7b77 start_wqthread + 15
)
2020-09-22 13:49:14.898322-0500 FlightBox PFD[3347:2884020] * 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                      0x00007fff2043a126 __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x00007fff20177f78 objc_exception_throw + 48
2   CoreAutoLayout                      0x00007fff58010d41 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] + 0
3   CoreAutoLayout                      0x00007fff58010fcd -[NSISEngine withBehaviors:performModifications:] + 25
4   UIKitCore                           0x00007fff24ab9bdc -[UIView(UIConstraintBasedLayout) _resetLayoutEngineHostConstraints] + 70
5   UIKitCore                           0x00007fff24bbd92f -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2715
6   QuartzCore                          0x00007fff27a3dd87 -[CALayer layoutSublayers] + 258
7   QuartzCore                          0x00007fff27a44239 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
8   QuartzCore                          0x00007fff27a4ff91 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
9   QuartzCore                          0x00007fff27990078 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
10  QuartzCore                          0x00007fff279c6e13 _ZN2CA11Transaction6commitEv + 783
11  QuartzCore                          0x00007fff279c7616 _ZN2CA11Transaction14release_threadEPv + 210
12  libsystem_pthread.dylib             0x00007fff5dcda054 _pthread_tsd_cleanup + 551
13  libsystem_pthread.dylib             0x00007fff5dcdc512 _pthread_exit + 70
14  libsystem_pthread.dylib             0x00007fff5dcd9ddd _pthread_wqthread_exit + 77
15  libsystem_pthread.dylib             0x00007fff5dcd8afc _pthread_wqthread + 481
16  libsystem_pthread.dylib             0x00007fff5dcd7b77 start_wqthread + 15
)


Normally this kind of thing can be tracked down by enabling the Main Thread Checker, but it does not appear to be working in this one case. I've enabled it and verified that the breakpoint it creates is active, but when the background thread does its thing the breakpoint is not called - the app simply crashes with the ever so useless:

Code Block
libc++abi.dylib: terminating with uncaught exception of type NSException

I'm frankly not sure what is creating this background thread - it does not appear to be associated with a queue. I'm not using any low-level APIs that would create a thread on my own, so I assume it's being executed by one of the libraries I'm using (or by one of the core iOS libs).

I'm going to start doing the usual things: disconnecting various bits of the app to see if I can get the crash to stop. If anyone knows how to get the Main Thread Checker to catch this, or might know what's going on here, please let me know. The app has been working fine for months when build on Xcode 11 and run on iOS 13.
Update: this appears to be specific to the iOS simulator. So far I have not been able to reproduce the issue on actual hardware. So far I have been testing on an iPad running 13.2.3. I'm in the processing of updating it to 14 to see if that makes a difference.

Solved. And it was NOT specific to the Simulator. It's definitely a change from iOS 13 to iOS 14.

The culprit turns out to have been a background thread spawned dispatched to set up an animation group. The setup function for the animation group was being run (for reasons I don't really understand) on a background utility thread. I fixed the issue by eliminating the dispatch to the background thread.

The offending code was from the Swift Pulse library by Chris Tews..

I still find it odd that this never offended in previous versions of iOS. Apparently iOS 14 is a bit pickier or more observant.


Getting NSInternalInconsistencyException crash after Xcode 12, iOS 14 Upgrade
 
 
Q