commit | 3e8b8130cda3b2564c8e9ee9f5825c0c34b8bc50 | [log] [tgz] |
---|---|---|
author | Jakub Turek <jkbturek@gmail.com> | Tue Jul 18 14:50:49 2023 +0200 |
committer | GitHub <noreply@github.com> | Tue Jul 18 12:50:49 2023 +0000 |
tree | af664a242dfa13344db9e6fb6de7f3ec17c66301 | |
parent | d4d761b74c78be3d6030edbf4337520fcc5df87d [diff] |
[video_player] Fix iOS crash with multiple players (#4202) This PR fixes crash in `video_player` package on iOS. https://github.com/flutter/flutter/issues/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.
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages
directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: