High Sierra avplayer deallocation crash

I’m on the latest JUCE from the dev branch. When I call close() on a videocomponent before it’s deleted (ScopedPointer) I get a crash in High Sierra with the following error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x608000013d10 of class AVPlayer was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x600000422e00> (
<NSKeyValueObservance 0x61000005de80: Observer: 0x61000000e330, Key path: rate, Options: <New: YES, Old: YES, Prior: NO> Context: 0x7f889c624e00, Property: 0x6080002411d0>
<NSKeyValueObservance 0x60000024b550: Observer: 0x61000000e330, Key path: status, Options: <New: YES, Old: NO, Prior: NO> Context: 0x7f889c624e00, Property: 0x61000005e5a0>
)'
terminating with uncaught exception of type NSException
abort() called

In juce_mac_video.h I found that while the detachPlayerStatusObserver and detachPlaybackObserver methods were being called, the conditionials in them were false, and no observers were being removed. While this doesn’t create a crash on my system (Mojave) it does for my users running High Sierra. If I call those two methods in close() before setting the player to nil, it prevents the crash:

Thanks Ed

Bumping this thread because I am getting reports of this exact same error/crash on macOS 10.12.6, and I’m not sure commit 38b24d7145595cde52b150e7cee56c4b074ed316 linked above solves the issue. (The problem looks like it’d still be there, judging by the code on the latest develop tip).

I’ve left a comment on that commit (as has @yairadix it seems), but I’ll also mention it here: the player is going to end up being nullptr before the check inside of detachPlayerStatusObserver(), so that detachment code will not run. If I move the detachment to happen before the player is set to nullptr, then the detaching seems to happen properly.

1 Like

I’ve been able to confirm with 3 separate users that making the above mentioned change fixes the crash, btw.

1 Like

Thanks for reporting. This should be fixed on develop here:

2 Likes