Repository navigation
android: don't touch a deleted player from surfaceDestroyed - #418
Open
abdelaziz-mahdy wants to merge 3 commits into
Open
abdelaziz-mahdy wants to merge 3 commits into
abdelaziz-mahdy wants to merge 3 commits into
Conversation
A VideoViewType.platformView player's native binding (players[surfaceId] in fvp_plugin.cpp) holds the raw mdkPlayerAPI* and is only erased by FvpVideoView.surfaceDestroyed/dispose. When the player is disposed before the SurfaceView is torn down, surfaceDestroyed later calls setDecoders() and updateNativeSurface() on the deleted player and the app dies with SIGSEGV in libfvp (nativeSetSurface). On an Android 16 emulator this happens on the first close every time if the VideoPlayer widget is removed and the controller disposed in the same frame. Player.disposeAsync() now calls MdkReleasePlayerSurfaces(player) right before deleting it. That releases every binding of the player, and in tunnel mode its decoder while the surface is still alive, the same way nativeSetSurface(null) does; a later surfaceDestroyed finds nothing.
Three jobs fail on every PR now that the stable channel is Flutter 3.50: - Android (any): Flutter 3.50 requires Gradle 9.3.1 and AGP 9.1.1 (and its Gradle plugin calls AGP 9 APIs, so skipping the version check does not help). The example moves to Gradle 9.3.1, AGP 9.1.1 and Kotlin 2.3.20. AGP 9's optimized resource shrinking needs non-final resource IDs, so android.nonFinalResIds goes back to its default (true); nothing in the example or plugin relies on final IDs. The Flutter 3.22 job restores the AGP 8 toolchain in a step, since 3.22 predates AGP 9. - iOS / macOS: video_player_avfoundation 2.12.2+ calls AVAsset.load(_:isolation:), which the Xcode 16.4 on macos-15 lacks. Both jobs move to macos-26 (Xcode 26.6). Verified locally: the example builds a release APK on Flutter 3.50 with JDK 17.
…ix/platform-view-dispose-crash
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
VideoViewType.platformViewplayer can crash the app when it is disposed before itsSurfaceViewis torn down.What happens
FvpVideoViewbinds its surface to the player natively (players[surfaceId]inandroid/fvp_plugin.cpp), and that binding keeps the rawmdkPlayerAPI*. The binding is only removed byFvpVideoView.surfaceDestroyed/dispose. IfPlayer.dispose()deletes the player first, the latersurfaceDestroyedcallssetDecoders()andupdateNativeSurface()on the deleted player:Repro
Android 16 emulator, fvp 0.40.0,
registerWith(options: {'tunnel': true}):This crashes on the first close, every time (2/2 runs of a 40-cycle loop). Removing the view 0.5 s before disposing does not crash, so it depends on which teardown runs first.
Fix
Player.disposeAsync()calls a newMdkReleasePlayerSurfaces(player)right before deleting the player. It releases every surface binding of that player, and in tunnel mode its decoder while the surface is still alive (the same stepsnativeSetSurface(null)already takes, now in a sharedreleaseSurface()helper). A latersurfaceDestroyedfinds no binding and returns.Same loop with this change: 20/20 cycles, no crash.
Relation to #413
Independent of #413 (which moves the delete off the UI isolate for #412), and the two compose: on top of #413 the release still runs on the owning isolate before the worker deletes the player. A branch with both is at abdelaziz-mahdy/fvp
app/dispose-fixes. On the same emulator it ran the crash loop 20/20 clean, disposing four texture players together held the main isolate 77-325 ms (938-2704 ms on 0.40.0), and an IPTV app on it did 12 play/close cycles with no crash or ANR.Stacked on #419, which fixes the three CI jobs that currently fail on every PR (Android on current Flutter, iOS, macOS). Merge #419 first and this PR reduces to its own commit (62a3d8f).