Skip to content

win-capture: Fix crash on GL context loss in fullscreen switch#13585

Open
sdenar228-alt wants to merge 1 commit into
obsproject:masterfrom
sdenar228-alt:win-capture-gl-fullscreen-crash
Open

win-capture: Fix crash on GL context loss in fullscreen switch#13585
sdenar228-alt wants to merge 1 commit into
obsproject:masterfrom
sdenar228-alt:win-capture-gl-fullscreen-crash

Conversation

@sdenar228-alt

Copy link
Copy Markdown

Description

The OpenGL graphics hook crashed the host game when the game destroyed
and recreated its GL context — for example LWJGL/GLFW based games such
as Minecraft toggling fullscreen, which changes the screen resolution.

The wglDeleteContext hook made the capture DC (data.hdc, captured at
init time and already invalid after the mode change) current with the
context being deleted, then ran the full gl_free() teardown. Issuing
GL and NV_DX_interop calls against a context that is being torn down
crashes inside the driver.

gl_free() now takes a gl_valid flag. In the delete-context path it is
called with false: only the API-independent resources (D3D11 device,
swap chain, dummy window, shared memory) are released, and the GL objects
and interop registrations are left for the driver to free together with
the context. The capture re-initializes on the next swap. All other
callers, where the game's context is current, pass true, so existing
behavior is unchanged.

Motivation and Context

Game Capture of OpenGL games (notably Minecraft) crashes the game on
every enter/exit of fullscreen while recording, because fullscreen
toggles recreate the GL context and change resolution.

How Has This Been Tested?

Built the graphics hook and full OBS (Windows x64, VS 2026), captured
Minecraft via Game Capture, and toggled fullscreen repeatedly. The
capture now releases and re-initializes cleanly without crashing the
game.

The OpenGL graphics hook's wglDeleteContext handler made the stale capture DC current and ran a full GL teardown when a game recreated its GL context (e.g. LWJGL/GLFW games such as Minecraft toggling fullscreen, which changes the screen resolution). Issuing GL and NV_DX_interop calls against a context that is being destroyed crashed the host game.

Free only the API-independent capture resources (D3D11 device, swap chain, dummy window, shared memory) when the context is going away and let the driver release the GL objects together with the context. The capture re-initializes on the next swap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant