Repository navigation
fix: crash when recording right after loading mp_coop_wall_5 - #382
Merged
Merged
Conversation
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.
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.
Starting a demo (
record, e.g. viasar_record_at 0) in the first few ticks after loading mp_coop_wall_5 crashes every time. srconfigs works around it withsar_record_at 120on that map.recordforces a full update, and the client then callsIMaterialSystem::CacheUsedMaterials, which ends inCTextureManager::ForceAllTexturesIntoHardware. That queues a draw for every listed texture without taking a reference. In the same frame the security room'svgui_movie_displayis recreated, and the old Bink material's textures are freed on the render thread before the queued preload reaches them. The render thread then callsIncrementReferenceCounton freed memory.This hooks
CacheUsedMaterialsand runs it withAllowThreading(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
0because 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_5andsar_record_atset 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.