map iterators aren't invalidated when you delete a different one

This commit is contained in:
Glenn Maynard
2002-10-19 18:56:48 +00:00
parent 40ef973094
commit 7783b51900
+8 -9
View File
@@ -141,20 +141,19 @@ void RageTextureManager::UnloadTexture( CString sTexturePath )
LOG->Trace("Performing texture garbage collection"); LOG->Trace("Performing texture garbage collection");
timeLastGarbageCollect = time(NULL); timeLastGarbageCollect = time(NULL);
// Chris: What is the proper way to iterate through this if deleting from map?
startovergc:
for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin(); for( std::map<CString, RageTexture*>::iterator i = m_mapPathToTexture.begin();
i != m_mapPathToTexture.end(); ++i) i != m_mapPathToTexture.end(); )
{ {
CString sPath = i->first; std::map<CString, RageTexture*>::iterator j = i;
RageTexture* pTexture = i->second; i++;
CString sPath = j->first;
RageTexture* pTexture = j->second;
if( pTexture->m_iRefCount==0 && 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 SAFE_DELETE( pTexture ); // free the texture
m_mapPathToTexture.erase(i); // and remove the key in the map m_mapPathToTexture.erase(j); // and remove the key in the map
goto startovergc;
} }
} }
} }