forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[video_player] Fix iOS crash with multiple players (flutter#4202)
This PR fixes crash in `video_player` package on iOS. flutter#124937 ### Detailed description I can observe the crash when displaying a couple of the different players (different URLs) inside a `ListView`. The crash happens inside of `AVFoundation` framework: ```objc [AVPlayer _createAndConfigureFigPlayerWithType:completionHandler:] ``` In order to debug the issue, I ran the application using the plugin with `Zombie Objects` inspection turned on. The `Zombie Objects` reports the following issue: ``` *** -[FLTVideoPlayer retainWeakReference]: message sent to deallocated instance 0x6030009b2e10 ``` This, in conjunction with the `NSKeyValueWillChange` line present in the stack trace led me to believe, that culprit is sending a KVO notification to the `FLTVideoPlayer` instance that's deallocated. Next, I examined the plugin code and identified one property that doesn't have the KVO removed. In `addObserversForItem:player:` method in `FLTVideoPlayerPlugin.m`: ``` [player addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:rateContext]; ``` The observer for `@"rate"` is never cleaned up. To be entirely sure that the issue comes from KVO that's not cleaned up, I've added the following class: ``` @implementation EmptyObserver - (void)observeValueForKeyPath:(NSString *)path ofObject:(id)object change:(NSDictionary *)change context:(void *)context {} @EnD ``` and registered the observation as follows (notice that `EmptyObserver` is never retained and deallocated instantly): ``` [player addObserver:[[EmptyObserver alloc] init] forKeyPath:@"rate" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:rateContext]; ``` The exception I got seems to be matching the underlying issue: ``` *** -[EmptyObserver retainWeakReference]: message sent to deallocated instance 0x6020001ceb70 ``` This means the fix for the issue is to add the following to `disposeSansEventChannel` method: ``` [self.player removeObserver:self forKeyPath:@"rate"]; ``` After applying the patch, I can no longer crash the player.
- Loading branch information
Showing
4 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters