I have an application that records a 5 second video and shows the playback using AVPlayer and AVPlayerLayer to the user.
The application works fine on iOS 12 and lower but the application crashes on iOS 13 as soon as video playback is initiated with the below stacktrace.
I have tried debugging to check from exactly where the crash is triggered but it never points to my code instead it points to libobjc.A.dylib.
(lldb) bt
* thread #8, queue = 'com.apple.coremedia.player.async.0x283425080.P/UA', stop reason = breakpoint 2.1
* frame #0: 0x000000018226408c libobjc.A.dylib`objc_exception_throw
frame #1: 0x0000000182a32934 Foundation`_AssertAutolayoutOnAllowedThreadsOnly + 324
frame #2: 0x000000018282ca64 Foundation`-[NSISEngine _optimizeWithoutRebuilding] + 72
frame #3: 0x000000018282c978 Foundation`-[NSISEngine optimize] + 116
frame #4: 0x000000018282c5e8 Foundation`-[NSISEngine performPendingChangeNotifications] + 116
frame #5: 0x0000000186a4b974 UIKitCore`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 3160
frame #6: 0x000000018225faf0 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 68
frame #7: 0x000000018909efc4 QuartzCore`-[CALayer layoutSublayers] + 292
frame #8: 0x00000001869b5270 UIKitCore`-[_UILabelLayer layoutSublayers] + 64
frame #9: 0x000000018909f2cc QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 484
frame #10: 0x00000001890b27b4 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 140
frame #11: 0x0000000188ff9ddc QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double) + 296
frame #12: 0x0000000189024e80 QuartzCore`CA::Transaction::commit() + 684
frame #13: 0x000000018c0570f4 MediaToolbox`FigLayerSynchronizerSynchronizeToMoment + 628
frame #14: 0x000000018c250900 MediaToolbox`remoteXPCItem_updateLayerSync + 1536
frame #15: 0x000000018c24f8a0 MediaToolbox`remoteXPCPlayer_connectVideoLayerToPlaybackItem + 220
frame #16: 0x000000018c257820 MediaToolbox`remoteXPCPlayer_AddToPlayQueue + 716
frame #17: 0x000000018c111580 MediaToolbox`playerasync_runOneCommand + 3624
frame #18: 0x000000018c117968 MediaToolbox`playerasync_runAsynchronousCommandOnQueue + 352
frame #19: 0x00000001821f1088 libdispatch.dylib`_dispatch_client_callout + 20
frame #20: 0x00000001821f7500 libdispatch.dylib`_dispatch_lane_serial_drain + 568
frame #21: 0x00000001821f7f2c libdispatch.dylib`_dispatch_lane_invoke + 368
frame #22: 0x0000000182200f9c libdispatch.dylib`_dispatch_workloop_worker_thread + 580
frame #23: 0x0000000182256aa4 libsystem_pthread.dylib`_pthread_wqthread + 280
(lldb) thread exception
(NSException *) exception = 0x0000000280f86df0 name: "NSInternalInconsistencyException" - reason: "Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread."
Message from debugger: Terminated due to signal 6