Fix crash from playing too many demos#363
Conversation
|
Oh yeah if you wanted to test this yourself you can use the command cache_print_summary at the end of every demo. As you play more unique maps in demos (without the fix active) you'll find ModelMesh grows rather rapidly! |
|
Love it! I'll just get you to regenerate Have you tested this on other mods too? NBD if not, it will correctly disable if the sig fails... |
|
Fixed both of those. On Linux though I had thought I had tested with the cleaned up build but apparently I hadn't and some changes did actually prevent it from working correctly. These changes fix that and also includes the offset stuff from this PR. The demos I originally tested Reloaded with were just quick few tick demos so they never actually dealt with the fun reloaded mechanic which repeatedly changes sv_cheats values. So when I just recently went to test with a normal demo I learned that FCVAR_CHEAT will forcibly disable this if sv_cheats are set to 0 during a demo (even with sar_demo_blacklist). That's the reason for the change to the cvar. |
This fixes the longstanding crash from playing back too many demos.
The basic issue was that when demos were played back it loaded in the models with a protected flag that prevented some of them from being deleted when the demo stopped. This meant that every time a new map was loaded it would slowly increase until the cache (256MB) didn't have enough space causing a crash :(. Repeatedly playing the demos of the same map doesn't cause the crash it's gotta be unique maps/model data.
I tried a few things to fix it, like forcibly unloading the models, that just crashes the game. Using built-in Valve commands (flush_locked explicitly flushes these resources) on demo stop, also just crashes the game. Just upping the cache limit to 512MB, which actually worked and made the cache sufficiently sized such that you could playback the entire SP or Coop campaign without crashing. It just wasn't a fix for the core issue so I abandoned it.
The solution I ended up on is whenever a demo stops it looks through the models cache and changes the flags to be ones the game is willing to cleanup. From there the game cleans them up appropriately by itself which nicely fixes the issue :).
Variable is sv_cheats protected because it has no need for working in a run, and it'd be pointless to waste time testing whether or not it can somehow actually break something.
Tested Portal 2 + all the mods on windows + linux (if Linux is supported). Pretty sure Valve just never changed anything related to this across all the engine versions so it kind of just worked out nicely.