From 90c2396da2109478316e123fc35bfffb807f41aa Mon Sep 17 00:00:00 2001 From: ShihChang Hsiung Date: Mon, 23 Sep 2019 16:17:02 -0700 Subject: [PATCH 1/2] video_player plugin can cause a crash on iPhone X running iOS 12 when disposing the video controller --- .../video_player/ios/Classes/VideoPlayerPlugin.m | 12 +++++++++++- packages/video_player/pubspec.yaml | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) 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 96374a133405..ee47cd813add 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+1 +version: 0.10.2+2 homepage: https://github.com/flutter/plugins/tree/master/packages/video_player flutter: From 8dfc68e24c51d33c8c9904d55e9a5e2288730c1d Mon Sep 17 00:00:00 2001 From: ShihChang Hsiung Date: Mon, 23 Sep 2019 16:28:50 -0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- packages/video_player/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/video_player/CHANGELOG.md b/packages/video_player/CHANGELOG.md index 4b1ce43d1465..474218c7f98a 100644 --- a/packages/video_player/CHANGELOG.md +++ b/packages/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.2+2 + +* 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+1 * Use DefaultHttpDataSourceFactory only when network schemas and use