8 Replies
      Latest reply on Jan 15, 2020 4:45 PM by jasontolliver
      e-kawakami Level 1 Level 1 (0 points)

        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

        • Re: NSInternalInconsistencyException on iOS 13 only
          Nikunj Gabani Level 1 Level 1 (0 points)

          I am getting same issue in iOS 13.

          Please let me know if you have resolved it.

          • Re: NSInternalInconsistencyException on iOS 13 only
            ccushman Level 1 Level 1 (0 points)

            Same issue.  App never used to crash before iOS 13, now code that works on iOS 12 crashes every time with the same error:

             

            2019-10-23 13:15:00.849602-0700 Mobility[909:269384] 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   Foundation                          0x00000001af3fecd4 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 2251988

            1   Foundation                          0x00000001af209fd4 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 200660

            2   Foundation                          0x00000001af209eec 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 200428

            3   Foundation                          0x00000001af209b60 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 199520

            4   UIKitCore                           0x00000001b33c08a0 82C949DD-37F6-35F7-B3EF-62BA342F6BF5 + 15181984

            5   UIKitCore                           0x00000001b33c12d8 82C949DD-37F6-35F7-B3EF-62BA342F6BF5 + 15184600

            6   QuartzCore                          0x00000001b58ad5f8 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 1377784

            7   QuartzCore                          0x00000001b58b1e28 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 1396264

            8   QuartzCore                          0x00000001b58bd894 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 1443988

            9   QuartzCore                          0x00000001b58069f0 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 694768

            10  QuartzCore                          0x00000001b5830890 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 866448

            11  QuartzCore                          0x00000001b5831814 5A4A8F86-A37D-3290-AC6A-9C03140FA5D3 + 870420

            12  libsystem_pthread.dylib             0x00000001aec48350 C3FA4F34-750F-362B-BEFE-835BFB15C0F8 + 58192

            13  libsystem_pthread.dylib             0x00000001aec45248 C3FA4F34-750F-362B-BEFE-835BFB15C0F8 + 45640

            14  libsystem_pthread.dylib             0x00000001aec3b870 pthread_exit + 36

            15  Foundation                          0x00000001af218984 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 260484

            16  Foundation                          0x00000001af3110c4 0DF2911E-80CB-3289-8A1E-ED0913D55A12 + 1278148

            17  libsystem_pthread.dylib             0x00000001aec451ec _pthread_start + 124

            18  libsystem_pthread.dylib             0x00000001aec48aec thread_start + 8

            )

            2019-10-23 13:15:00.853694-0700 Mobility[909:269384] *** 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:

            (0x1aef2898c 0x1aec510a4 0x1af3fed64 0x1af209fd4 0x1af209eec 0x1af209b60 0x1b33c08a0 0x1b33c12d8 0x1b58ad5f8 0x1b58b1e28 0x1b58bd894 0x1b58069f0 0x1b5830890 0x1b5831814 0x1aec48350 0x1aec45248 0x1aec3b870 0x1af218984 0x1af3110c4 0x1aec451ec 0x1aec48aec)

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

            Exception: EXC_BREAKPOINT (code=1, subcode=0x1aeb908c0)

              • Re: NSInternalInconsistencyException on iOS 13 only
                ccushman Level 1 Level 1 (0 points)

                More information on mine.

                 

                I have an IBOutlet property which was being tied to touchUpInside for a button. This worked FINE before iOS 13.


                After iOS 13 update -

                In the IBOutlet method - i have network calls that need to be on a BG thread and I have ui calls that need to be on the main thread.

                 

                When using IBOutlet - no matter how I dispatch - I was getting this error EVERY time.  I tried multiple different ways to get the UI and Main thread updates to happen on the correct threads and I could not find any way to make it work.

                 

                I removed my IBOutlet - and added a target to my button using addTarget - pointed to THE SAME METHOD - and it worked.

                 

                For me - I think there may have been something going on with the IBOutlet and my attempts to use the background thread.  But for now I've resolved by not using the IBOutlet.

                 

                Maybe this will be helpful for someone ¯\_(ツ)_/¯

              • Re: NSInternalInconsistencyException on iOS 13 only
                jasontolliver Level 1 Level 1 (0 points)

                I dealt with the same thing.  I was able to find the offending logic using the trick found here: https://stackoverflow.com/questions/58087536/modifications-to-the-layout-engine-must-not-be-performed-from-a-background-thr#answer-59299616

                 

                After that, I simply wrapped it in

                dispatch_async(dispatch_get_main_queue(), ^{
                  // offending code goes in here
                });

                 

                With this, I was able to make sure my view was presented by the main thread, and no crash ¯\_(ツ)_/¯