Skip to content

fix: crash when recording right after loading mp_coop_wall_5 - #382

Merged
ThisAMJ merged 2 commits into
p2sr:masterfrom
PortalRex:fix/wall5-texture-preload-crash
Oct 25, 2026
Merged

ThisAMJ merged 2 commits into
p2sr:masterfrom
PortalRex:fix/wall5-texture-preload-crash

Conversation

@PortalRex

@PortalRex PortalRex commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Starting a demo (record, e.g. via sar_record_at 0) in the first few ticks after loading mp_coop_wall_5 crashes every time. srconfigs works around it with sar_record_at 120 on that map.

record forces a full update, and the client then calls IMaterialSystem::CacheUsedMaterials, which ends in CTextureManager::ForceAllTexturesIntoHardware. That queues a draw for every listed texture without taking a reference. In the same frame the security room's vgui_movie_display is recreated, and the old Bink material's textures are freed on the render thread before the queued preload reaches them. The render thread then calls IncrementReferenceCount on freed memory.

This hooks CacheUsedMaterials and runs it with AllowThreading(false), which flushes the pending queue first. The previous threading state is restored afterwards, the same way the engine handles screenshots. It only runs on loads and full updates.

The service thread argument is 0 because that's what the engine passes unless launched with -swapcores, and Portal 2's materialsystem never reads it.

Enabled for Portal 2 (10090) on Windows only. Other games keep their existing behaviour, since I've only verified the vtable slots (78 and 135) on that build.

Tested with ss_map mp_coop_wall_5 and sar_record_at set to 0, 3 and 10. Before: 5 of 5 crashed. After: 5 of 5 survived, the demo records from tick 0, and queued rendering resumes after the sync.

Once a SAR release includes this, the wall 5 workaround in srconfigs can be removed.

Clanked up by Claude, thoroughly testing by yours truly, bald.

PortalRex and others added 2 commits October 23, 2026 17:27
CTextureManager::ForceAllTexturesIntoHardware queues a draw of every
listed texture without referencing it. After a full update (e.g. `record`
right after a load) textures whose last reference was dropped that frame
are freed by the render thread before it reaches the preload draw, which
then crashes. mp_coop_wall_5's movie screens hit this every time with
sar_record_at 0. Run CacheUsedMaterials with threading off, as the engine
does around screenshots.
@ThisAMJ
ThisAMJ merged commit dc8d484 into p2sr:master Oct 25, 2026
2 checks passed
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.

2 participants