win-capture: Fix crash on GL context loss in fullscreen switch#13585
Open
sdenar228-alt wants to merge 1 commit into
Open
win-capture: Fix crash on GL context loss in fullscreen switch#13585sdenar228-alt wants to merge 1 commit into
sdenar228-alt wants to merge 1 commit into
Conversation
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.
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.
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
wglDeleteContexthook made the capture DC (data.hdc, captured atinit time and already invalid after the mode change) current with the
context being deleted, then ran the full
gl_free()teardown. IssuingGL and NV_DX_interop calls against a context that is being torn down
crashes inside the driver.
gl_free()now takes agl_validflag. In the delete-context path it iscalled 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 existingbehavior 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.