Repository navigation
fix(windows): don't tear down the native player while an open/seek or frame read is using it - #256
Open
muthuraj57 wants to merge 1 commit into
Open
muthuraj57 wants to merge 1 commit into
muthuraj57 wants to merge 1 commit into
Conversation
… frame read is using it Two races in dispose() crashed with EXCEPTION_ACCESS_VIOLATION (kdroidFilter#249): - It never took mediaOperationMutex, so disposing while openUri was inside native OpenMedia destroyed the instance underneath it (reproduced: removing a playing player from composition shortly after opening crashes in nOpenMedia). dispose() now tears down while holding the mutex, waiting up to 2 s; if an open is still blocked in native code after that (slow HTTP connect), the teardown finishes on a background thread once it returns. - It waited while jobToJoin.isActive after cancel(), but a cancelled job is no longer active, so it never waited for the producer to leave ReadVideoFrame. It now waits for isCompleted.
muthuraj57
force-pushed
the
fix-windows-dispose-race
branch
from
October 24, 2026 11:31
df0985a to
b7d7689
Compare
This branch has not been deployed
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.
Summary
Fixes #249. Two races in
dispose()crash withEXCEPTION_ACCESS_VIOLATION:dispose()never takesmediaOperationMutex, so removing the player from composition whileopenUriis inside nativeOpenMediadestroys the instance underneath it. Reproduced on Windows 11: a player removed from composition 0.3–1.2 s afteropenUri(PLAY)on a local 720p MP4 crashes inNativeVideoPlayer.dllwithWindowsNativeBridge.nOpenMediaon the stack, in the first round.dispose()now does the native teardown while holding the mutex, spinning (not suspending, as it often runs on the EDT) for up to 2 s; if an open is still blocked in native code after that (e.g. a slow HTTP connect), the teardown finishes on a background thread once the open returns.jobToJoin.cancel()it waitedwhile (jobToJoin.isActive …), but a cancelled job is no longer active, so it never waited for the producer to leaveReadVideoFrame. It now waits forisCompleted.Test plan
Windows 11 x64, a player shown then removed from composition 20 times (random 0.3–1.2 s apart) while playing a local 720p H.264 MP4:
EXCEPTION_ACCESS_VIOLATION,nOpenMediaon the stack):mediaplayer:compileKotlinJvm,ktlintCheckadds no findings