Fix black video preview in burn-in / visual sync windows (#12205)#12235
Merged
Conversation
Windows that open a video right from their Loaded event (the burn-in and visual sync previews) issued mpv's "loadfile" before the rendering surface had lazily initialized the mpv core (mpv_initialize runs on the OpenGL control's first render pass). The command failed with MPV_ERROR_UNINITIALIZED and was never retried, leaving the preview black - along with all follow-up calls (pause, SetAudioTrack: "core not initialized"). The main window was unaffected only because its player idles until the user opens a file, long after the surface initialized. Track core initialization in LibMpvDynamicPlayer (set after mpv_initialize succeeds in all four init paths: OpenGL, Metal, software, native wid) and make LoadFile/LoadAudio wait (bounded, 5s) for it before sending commands. The wait is async on the UI thread, so the first render pass - which performs the initialization - is not blocked. Fixes #12205 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
The video preview in the burn-in and visual sync windows stayed black until the window was resized/maximized (#12205). The main window's player was unaffected.
Root cause
Those windows open the video right from their
Loadedevent, but the mpv core is initialized lazily by the rendering surface — e.g. the OpenGL control callsInitializeWithOpenGL(→mpv_initialize) on its first render pass, which hasn't happened yet at that point. Theloadfilecommand therefore failed withMPV_ERROR_UNINITIALIZED(-3) and was never retried; all follow-up calls failed the same way (pause,SetAudioTrack: "core not initialized" in error-log.txt). Traced by logging theloadfileresult:The main window only works because its player idles until the user opens a file, long after the surface initialized.
Fix
In
LibMpvDynamicPlayer:_coreInitializedflag, set aftermpv_initializesucceeds in all four init paths (OpenGL, Metal, software rendering, native widInitialize()).LoadFile/LoadAudionow awaitWaitForCoreInitializedAsync()(25 ms polls, 5 s cap) before issuingloadfile. The wait is async on the UI thread, so the first render pass — which performs the initialization — is not blocked; the load fires right after init completes.If the surface never initializes (e.g. mpv missing), the bounded wait falls through and the command fails/logs exactly as before.
Testing
Fixes #12205
🤖 Generated with Claude Code