diff --git a/packages/video_player/CHANGELOG.md b/packages/video_player/CHANGELOG.md index ca3a82880b10..8d69d9827c3c 100644 --- a/packages/video_player/CHANGELOG.md +++ b/packages/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.2+3 + +* iOS: Fix an issue where video_player plugin can cause a crash on iPhone X running iOS 12 when disposing the video controller. + ## 0.10.2+2 * Update and migrate iOS example project. diff --git a/packages/video_player/ios/Classes/VideoPlayerPlugin.m b/packages/video_player/ios/Classes/VideoPlayerPlugin.m index bf449ec0e8e2..c15106f3a702 100644 --- a/packages/video_player/ios/Classes/VideoPlayerPlugin.m +++ b/packages/video_player/ios/Classes/VideoPlayerPlugin.m @@ -483,11 +483,21 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { } else { NSDictionary* argsMap = call.arguments; int64_t textureId = ((NSNumber*)argsMap[@"textureId"]).unsignedIntegerValue; - FLTVideoPlayer* player = _players[@(textureId)]; + __block FLTVideoPlayer* player = _players[@(textureId)]; if ([@"dispose" isEqualToString:call.method]) { [_registry unregisterTexture:textureId]; [_players removeObjectForKey:@(textureId)]; [player dispose]; + + // TODO: remove the line below when the race condition is resolved: + // https://github.com/flutter/flutter/issues/41125 + // Hang on to the player for a second to give time for the texture to grab the last buffer + // This can happen if the display link just notified that a frame was ready before this dispose gets called + // In this case, even though we unregister the texture id, the gpu thread has been scheduled to grab the buffer + // and if the player is deallocated, we'll crash + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + player = nil; + }); result(nil); } else if ([@"setLooping" isEqualToString:call.method]) { [player setIsLooping:[argsMap[@"looping"] boolValue]]; diff --git a/packages/video_player/pubspec.yaml b/packages/video_player/pubspec.yaml index ee47cd813add..4c32a11a851a 100644 --- a/packages/video_player/pubspec.yaml +++ b/packages/video_player/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player description: Flutter plugin for displaying inline video with other Flutter widgets on Android and iOS. author: Flutter Team -version: 0.10.2+2 +version: 0.10.2+3 homepage: https://github.com/flutter/plugins/tree/master/packages/video_player flutter: