Prevent segfault on shutdown

This should also happen on Windows, I'm really surprised
this hasn't been noticed there
This commit is contained in:
Daniel Gibson 2012-12-23 05:14:48 +01:00
parent ba126dde3a
commit cca3053069

View file

@ -168,7 +168,23 @@ ID_INLINE void idStrPool::FreeString( const idPoolStr* poolStr )
{
int i, hash;
assert( poolStr->numUsers >= 1 );
/*
* DG: numUsers can actually be 0 when shutting down the game, because then
* first idCommonLocal::Quit() -> idCommonLocal::Shutdown() -> idLib::Shutdown()
* -> idDict::Shutdown() -> idDict::globalKeys.Clear() and idDict::globalVars.Clear()
* is called and then, from destructors,
* ~idSessionLocal() => destroy idDict titleStorageVars -> ~idDict() -> idDict::Clear()
* -> idDict::globalVars.FreeString() and idDict::globalKeys.FreeString() (this function)
* is called, leading here.
* So just return if poolStr->numUsers < 1, instead of segfaulting/asserting below
* when i == -1 because nothing was found here. As there is no nice way to find out if
* we're shutting down (at this point) just get rid of the following assertion:
* assert( poolStr->numUsers >= 1 );
*/
if( poolStr->numUsers < 1 )
return;
// DG end
assert( poolStr->pool == this );
poolStr->numUsers--;