tvOS SDK 4.2.1 - Crash caused by the layout modification outside of the main thread

708 views
Skip to first unread message

Arkadiusz Matecki

unread,
Mar 4, 2020, 10:07:31 AM3/4/20
to Interactive Media Ads SDK
Hi All,
I'm using the latest SDK (4.2.1) with tvOS 13 device. I'm getting auto layout crashes while playing ads:

*** 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                      0x00007fff23340a5e __exceptionPreprocess + 350

1   libobjc.A.dylib                     0x00007fff3fbf44b1 objc_exception_throw + 48

2   Foundation                          0x00007fff24c45bc4 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] + 0

3   Foundation                          0x00007fff24c45832 -[NSISEngine _optimizeWithoutRebuilding] + 54

4   Foundation                          0x00007fff24c45765 -[NSISEngine optimize] + 100

5   Foundation                          0x00007fff24c40484 -[NSISEngine performPendingChangeNotifications] + 82

6   UIKitCore                           0x00007fff39b9c01e -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 3642

7   QuartzCore                          0x00007fff290756f9 -[CALayer layoutSublayers] + 255

8   UIKitCore                           0x00007fff39afbf73 -[_UILabelLayer layoutSublayers] + 55

9   QuartzCore                          0x00007fff2907b8db _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517

10  QuartzCore                          0x00007fff290871c2 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80

11  QuartzCore                          0x00007fff28fcf25c _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 316

12  QuartzCore                          0x00007fff290043d6 _ZN2CA11Transaction6commitEv + 638

13  QuartzCore                          0x00007fff2900528e _ZN2CA11Transaction14release_threadEPv + 210

14  libsystem_pthread.dylib             0x00007fff40beb6ab _pthread_tsd_cleanup + 551

15  libsystem_pthread.dylib             0x00007fff40bee655 _pthread_exit + 70

16  libsystem_pthread.dylib             0x00007fff40beb43a _pthread_wqthread_exit + 74

17  libsystem_pthread.dylib             0x00007fff40bea644 _pthread_wqthread + 472

18  libsystem_pthread.dylib             0x00007fff40bea3fd start_wqthread + 13


Since I'm using AVPlayerViewController I can't force using the main thread with DispatchQueue.main. This crash never happens without ads, so I assume something is posted outside the main thread inside the SDK. I tried finding it with Thread Sanitizer and Main Thread Checker, without success. Could you help?


Thanks


Arek

IMA SDK

unread,
Mar 4, 2020, 4:49:20 PM3/4/20
to arkadius...@dazn.com, ima...@googlegroups.com
Hi,

Thank you for reaching out to us. We were not able to reproduce the behavior that you're seeing with the crash caused by the layout modification outside of the main thread. We've run our
tvOS BasicExample sample app against the tvOSv13.3 of the simulator, the ads were displayed successfully, no crash occurred. The issue seems to be with your implementation, we would recommend you to review it while debugging it against our tvOS BasicExample.

Regards,
Arnaud Casame
IMA SDK Team


ref:_00D1U1174p._5001UXU425:ref
Screen Shot 2020-03-04 at 3.04.17 PM.png

Arkadiusz Matecki

unread,
Mar 5, 2020, 6:01:39 AM3/5/20
to Interactive Media Ads SDK
After some investigation I was able to find the source of the issue. Our app was starting the playback right after creating AVPlayer, when we integrated IMA SDK this setup resulted in crashes. You can reproduce it in BasicExample, after:

    self.playerViewController = [[AVPlayerViewController alloc] init];

    self.playerViewController.player = player;
add this line:
    [self.playerViewController.player play]; 
Run the app, you'll notice warnings in the Xcode console:

[Assert] UIView animation API is being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.


Eventually the app will crash. I don't know if it's a bug in the IMA SDK, or just misuse on my part, but it's was hard to find, because the stack trace wasn't pointing to anything in my code

IMA SDK

unread,
Mar 5, 2020, 3:08:31 PM3/5/20
to arkadius...@dazn.com, ima...@googlegroups.com
Hi,

I was able to reproduce the crash that you're encountering when you call play on the AVPlayer instance. However, this behavior is not caused by an IMA SDK bug, it is the result of your implementation fighting with the IMA SDK to have the control of the video and ad playback. The IMA SDK takes care of playing the video content and the ad for you, if you want to have manual control of the playbacks, you can implement the Manual Ad Break Playback feature.


Regards,
Arnaud Casame
IMA SDK Team


ref:_00D1U1174p._5001UXU425:ref
Reply all
Reply to author
Forward
0 new messages