video: unify screen-surface teardown into one helper - #3
Open
ForkedInTime wants to merge 1 commit into
Open
Conversation
LbScreenSetup and LbScreenReset each open-coded the same surface/GL teardown, and they had drifted: LbScreenReset cleared both lbDrawSurface and lbScreenSurface, but LbScreenSetup cleared only lbDrawSurface. In GL-present mode those two globals alias the same owned surface, so after LbScreenSetup's teardown lbScreenSurface was left dangling at a freed surface (and stayed dangling on any early-return failure path before the new surface is created). Extract the shared logic into lb_release_screen_surfaces() and route both callers through it, so they can't diverge again. This nulls lbScreenSurface in the setup path too. Also drop the dead 'prevScreenSurf' capture + empty if-block in LbScreenSetup, and restructure the GL/second-surface free to avoid the #ifndef-straddling else (clang-tidy misleading-indentation). Behavior-preserving hardening; no functional change on the happy path. Builds clean.
ForkedInTime
force-pushed
the
harden/screen-surface-teardown
branch
from
August 3, 2026 22:34
2363a5a to
5d9a045
Compare
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.
What
Extract the duplicated screen-surface / GL-backend teardown in
bflib_video.cinto a singlelb_release_screen_surfaces()helper, and route bothLbScreenSetupandLbScreenResetthrough it.Why
The two functions each open-coded the same teardown, and they had drifted:
LbScreenResetcleared bothlbDrawSurfaceandlbScreenSurface.LbScreenSetupcleared onlylbDrawSurface.In GL-present mode those two globals alias the same owned surface, so after
LbScreenSetup's teardownlbScreenSurfacewas left dangling at a just-freed surface — and stayed dangling on any early-return failure path (SDL_SetWindowDisplayMode/SDL_SetWindowFullscreen/window-create failure) before the new surface is assigned.This is latent hardening: it was not the cause of the recent level-transition crash (that was a config/packaging issue, fixed separately), and repeated in-game resolution switches (
Alt+R, the same teardown path) don't trip it in practice. But the asymmetry is a real dangling-pointer hazard and an easy trap for the next change.Changes
static void lb_release_screen_surfaces(void)— frees the draw/second surface (and shuts down the GL backend if active), then clearslbHasSecondSurface,lbDrawSurface,lbScreenSurface, andlbScreenInitialised. Documents why both surface pointers must be cleared (GL alias) and why the CPU window-surface must not be freed.LbScreenSetupandLbScreenResetnow call the helper instead of duplicating it — they can't diverge again.prevScreenSurfcapture + emptyif (prevScreenSurf != NULL) {}block inLbScreenSetup.freed_draw_surfaceflag to drop the#ifndef _WIN32-straddlingelse(clears a clang-tidymisleading-indentationwarning).Verification
Behavior-preserving on the happy path; the only functional change is nulling
lbScreenSurfacein the setup teardown (strictly safer — it's reassigned before use, or left NULL instead of dangling on failure). Engine builds clean (make -f linux.mk, no new warnings onbflib_video.c).🤖 Generated with Claude Code