Crash in iOS 18 regarding [AVPlayerController _observeValueForKeyPath:oldValue:newValue:]

There are significant crash reports coming from iOS 18 users regarding AVKit framework that starts from this line [AVPlayerController _observeValueForKeyPath:oldValue:newValue:] which seems to be coming from iOS internal SDK. There are 2 kinds of crash we found:

  1. UI modification on background thread

From the stack trace it seems like when AVPictureInPictureController is being deallocated and its view is being removed from superview somehow the code is being executed in background thread because there is this line there _AssertAutoLayoutOnAllowedThreadsOnly highlighted before the crash.

But I’ve checked our code that plays around AVPictureInPictureController, in the locations where we would deallocate the object it will always be called on main thread which are insideviewDidLoad and deinit inside UIViewController class. From the log, it seems like the crash happened when user try to open another content when PIP player is active resulting in the current PIP instance will be replaced with a new one. My suspect is the observation logic inside AVPlayerController could be the hint to this issue, probably something broken over there since this issue happened across our app versions on iOS 18 users only.

Unfortunately, I was unable to reproduce this issue yet but one of my colleagues reproduced it once but haven’t been able to do it again since. The reports keep raising each day up to 1.3k events in the last 30 days now.

  1. Over release object

This one has lower reports than the first one but I decided to include it since it might have relevant information regarding the first crash since the starting stack trace is similar. The crash timing seems to be similar to the first one, where we deallocate existing AVPictureInPictureController and later replace it with a new one and also found only in iOS 18 users which also refers to [AVPlayerController _observeValueForKeyPath:oldValue:newValue:]. I also was unable to reproduce this issue so far.

Oh, and both of the issues happened on both iPhone and iPad.

We’d appreciate any advice on what we can do to avoid this in the future and probably any hint on why it could happened.

I have reported this issue with bug number: FB15620734

I also attached one sample crash report for each of the crashes here.

I have the same problem, and I have no idea yet.

Hi everyone,

Exact same issue here, with the exact same stacktrace in the com.apple.avkit.seekQueue

The crash is also reported by iOS18.1 users

Sadly, we haven't been able to build a minimalistic project that shows the issue.

Happy hacking, Iban

same problem

same here

我遇到了完全相同的问题,也是发生在开启pip,打开另一个节目的过程中。在创建新的AVPictureInPictureController对象之前,我会先resetpip。 这里会把旧的AVPictureInPictureController strong对象pipvc设置为nil,删除掉这句代码发现就好了。

主要思路应该就是避免崩溃这个时机触发到AVPictureInPictureController dealloc

Thank you for the suggestion @SepCode, we implemented a fix that retains and reuses the AVPictureInPictureController for subsequent Picture in Picture sessions. The crash has now disappeared.

It would nice for Apple to update the PiP documentation about this, because it is very light and is missing lots of important things like this.

This crash is happening for me also, but in the dealloc I am not even assigning nil to AVPictureInPictureController object.

Crash in iOS 18 regarding [AVPlayerController _observeValueForKeyPath:oldValue:newValue:]
 
 
Q