Skip to content

Feature/sv demo cinema - mem leak fix + playdemo wait for clients#14

Open
sedawkgrep wants to merge 6 commits into
themuffinator:mainfrom
sedawkgrep:feature/sv-demo-cinema
Open

Feature/sv demo cinema - mem leak fix + playdemo wait for clients#14
sedawkgrep wants to merge 6 commits into
themuffinator:mainfrom
sedawkgrep:feature/sv-demo-cinema

Conversation

@sedawkgrep

@sedawkgrep sedawkgrep commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixed: Server (demo cinema mode) crashes after too many consecutive sv_playdemo commands due to memory leak.

Fixed: an errant condition for unknown commands while in sv_playdemo mode.

Fixed: sv_playdemo will not attempt to play a demo for a map it does not have.

Improvement: Server will not begin playing a demo until it has at least one fully connected client.

Added sv_playingdemo command to see the status of the server.

sedawkgrep and others added 6 commits July 13, 2026 05:54
sv_playdemo now holds on the demo's first frame until a real client
reaches CS_ACTIVE, instead of burning through snapshots against an
empty server. SV_Frame gates the per-tick SV_DemoAdvance() call on a
new one-way latch (sv.demoWaitingForViewer), reusing the same
sv.time-only "hold" pattern already used for the end-of-demo case.

Also fixes a crash ("Hunk_Alloc failed") after replaying ~4-5 demos:
SV_SpawnDemoServer hunk-allocates snapshot entity storage on every
call but was skipping Hunk_Clear() beforehand, so each sv_playdemo
leaked another full snapshotEntities allocation until the hunk filled
up. Clear the hunk (and collision map, unused during demo cinema)
before that allocation, matching SV_SpawnServer's normal map-load path.
sv_playdemo sets sv.state = SS_GAME while leaving gvm null, so any
unrecognized console command (e.g. accidentally typing "demo" on a
dedicated server) fell through to VM_Call(gvm, GAME_CONSOLE_COMMAND)
with gvm == NULL, crashing with "VM_Call with NULL vm". Also tag that
fatal error with the callnum so a null-vm crash is diagnosable without
a debugger next time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
sv.demoPlayback was purely internal, so there was no way to tell a
server was stuck in sv_playdemo cinema mode without checking logs.
Add sv_playingDemo (CVAR_SERVERINFO | CVAR_ROM, same pattern as
mapname) so it's queryable on the local console, in CS_SERVERINFO for
connected clients, and via remote getinfo/getstatus.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
SV_SpawnDemoServer intentionally skips CM_LoadMap (no collision data
needed for snapshot replay), so unlike a normal map spawn it never got
a missing-BSP check. Cinema would start anyway, leaving every
connecting client to independently discover the map is missing and
disconnect instead of one clear server-side error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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