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