map iterators aren't invalidated when you delete a different one
This commit is contained in:
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user