Fix macOS black video after re-parenting the shared player view

The player video surface is a single shared MPVOGLView that is re-parented
between the mini-bar container (main window) and the expanded-player sheet
(a separate sheet window). When presenting the sheet, the new container
attaches the shared view before the old mini-bar container tears down, so
the old container's viewWillMove(toSuperview: nil) was ripping the shared
view out of its new home via removeFromSuperview() — leaving it with no
window and a black surface. Symmetric, so it also blanked the mini-bar
preview after collapsing.

Only detach the shared view if it still belongs to the container
(superview === self). Also force a repaint on window reattach so a paused
frame redraws, and extend the onAppear resumeRendering to macOS.
This commit is contained in:
Arkadiusz Fal
2026-05-25 19:46:35 +02:00
parent fe4e3c531a
commit 5f49f2d022
3 changed files with 23 additions and 5 deletions

View File

@@ -170,6 +170,12 @@ final class MPVOGLView: NSView {
// Update contents scale for new window
videoLayer?.contentsScale = window.backingScaleFactor
// Reattaching (e.g. macOS player sheet dismissed via ESC then re-expanded)
// detaches this shared view without stopping playback. macOS drawing is
// pull-based, so force a redraw to repaint the current frame otherwise
// the layer stays black until MPV emits a new frame (never, if paused).
resumeRendering()
}
}