From 7783b5190078085d7d6384a81fb2c57c8d9b1cf6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 19 Oct 2002 18:56:48 +0000 Subject: [PATCH] map iterators aren't invalidated when you delete a different one --- stepmania/src/RageTextureManager.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index 2d88c7898a..c0359629a1 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -141,20 +141,19 @@ void RageTextureManager::UnloadTexture( CString sTexturePath ) LOG->Trace("Performing texture garbage collection"); timeLastGarbageCollect = time(NULL); - // Chris: What is the proper way to iterate through this if deleting from map? -startovergc: - for( std::map::iterator i = m_mapPathToTexture.begin(); - i != m_mapPathToTexture.end(); ++i) + i != m_mapPathToTexture.end(); ) { - CString sPath = i->first; - RageTexture* pTexture = i->second; + std::map::iterator j = i; + i++; + + CString sPath = j->first; + RageTexture* pTexture = j->second; if( pTexture->m_iRefCount==0 && - pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload < time(NULL) ) + pTexture->m_iTimeOfLastUnload+m_iSecondsBeforeUnload <= time(NULL) ) { SAFE_DELETE( pTexture ); // free the texture - m_mapPathToTexture.erase(i); // and remove the key in the map - goto startovergc; + m_mapPathToTexture.erase(j); // and remove the key in the map } } }