diff --git a/src/Font.cpp b/src/Font.cpp index 4fd73591d2..3c3cdf1e4a 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -728,7 +728,6 @@ void Font::Load( const RString &sIniPath, RString sChars ) Font subfont; subfont.Load(fPath,""); MergeFont(subfont); - //FONT->UnloadFont(subfont); } } diff --git a/src/FontManager.cpp b/src/FontManager.cpp index 1500a78e29..380f00384b 100644 --- a/src/FontManager.cpp +++ b/src/FontManager.cpp @@ -22,7 +22,7 @@ FontManager::~FontManager() { const FontName &fn = i->first; Font* pFont = i->second; - if(pFont->m_iRefCount>0) { + if(pFont->m_iRefCount > 0) { LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", fn.first.c_str(), pFont->m_iRefCount ); } delete pFont; @@ -53,14 +53,13 @@ Font* FontManager::LoadFont( const RString &sFontOrTextureFilePath, RString sCha { pFont=p->second; pFont->m_iRefCount++; - } - else { - pFont= new Font; - pFont->Load(sFontOrTextureFilePath, sChars); - g_mapPathToFont[NewName] = pFont; + return pFont; } - return pFont; + Font *f = new Font; + f->Load(sFontOrTextureFilePath, sChars); + g_mapPathToFont[NewName] = f; + return f; } Font *FontManager::CopyFont( Font *pFont ) @@ -79,16 +78,22 @@ void FontManager::UnloadFont( Font *fp ) if(i->second != fp) continue; - ASSERT_M(fp->m_iRefCount>0,"Attempting to unload a font with zero ref count!"); + ASSERT_M(fp->m_iRefCount > 0,"Attempting to unload a font with zero ref count!"); i->second->m_iRefCount--; + if( fp->m_iRefCount == 0 ) + { + delete i->second; // free the texture + g_mapPathToFont.erase( i ); // and remove the key in the map + } return; } FAIL_M( ssprintf("Unloaded an unknown font (%p)", fp) ); } +/* void FontManager::PruneFonts() { for( std::map::iterator i = g_mapPathToFont.begin();i != g_mapPathToFont.end();) { Font *fp=i->second; @@ -101,6 +106,7 @@ void FontManager::PruneFonts() { } } } +*/ /* * (c) 2001-2003 Chris Danford, Glenn Maynard diff --git a/src/FontManager.h b/src/FontManager.h index 9124d694f9..f3159ab006 100644 --- a/src/FontManager.h +++ b/src/FontManager.h @@ -15,7 +15,7 @@ public: Font* LoadFont( const RString &sFontOrTextureFilePath, RString sChars = "" ); Font *CopyFont( Font *pFont ); void UnloadFont( Font *fp ); - void PruneFonts(); + //void PruneFonts(); /* Warning: This reloads fonts completely, so all BitmapTexts need to be * reset, too. If this isn't done, best case they end up with old font diff --git a/src/ScreenManager.cpp b/src/ScreenManager.cpp index 15dcc3bc32..ed8549f05d 100644 --- a/src/ScreenManager.cpp +++ b/src/ScreenManager.cpp @@ -76,7 +76,7 @@ ScreenManager* SCREENMAN = NULL; // global and accessable from anywhere in our program static Preference g_bDelayedScreenLoad( "DelayedScreenLoad", false ); -static Preference g_bPruneFonts( "PruneFonts", true ); +//static Preference g_bPruneFonts( "PruneFonts", true ); // Screen registration static map *g_pmapRegistrees = NULL; @@ -592,9 +592,11 @@ void ScreenManager::PrepareScreen( const RString &sScreenName ) } // Prune any unused fonts now that we have had a chance to reference the fonts + /* if(g_bPruneFonts) { FONT->PruneFonts(); } + */ TEXTUREMAN->DiagnosticOutput(); } @@ -690,17 +692,19 @@ void ScreenManager::LoadDelayedScreen() * cleanup, so it doesn't get deleted by cleanup. */ bool bLoaded = ActivatePreparedScreenAndBackground( sScreenName ); - bool deletePrepared=g_setGroupedScreens.find(sScreenName) == g_setGroupedScreens.end(); - - /* It's time to delete all old prepared screens. Depending on DelayedScreenLoad, - * we can either delete the screens before or after we load the new screen. - * Either way, we must remove them from the prepared list before we prepare - * new screens. - * If DelayedScreenLoad is true, delete them now; this lowers memory - * requirements, but results in redundant loads as we unload common data. */ - if( deletePrepared && g_bDelayedScreenLoad ) { - DeletePreparedScreens(); - deletePrepared=false; + vector apActorsToDelete; + if( g_setGroupedScreens.find(sScreenName) == g_setGroupedScreens.end() ) + { + /* It's time to delete all old prepared screens. Depending on + * DelayedScreenLoad, we can either delete the screens before or after + * we load the new screen. Either way, we must remove them from the + * prepared list before we prepare new screens. + * If DelayedScreenLoad is true, delete them now; this lowers memory + * requirements, but results in redundant loads as we unload common data. */ + if( g_bDelayedScreenLoad ) + DeletePreparedScreens(); + else + GrabPreparedActors( apActorsToDelete ); } // If the screen wasn't already prepared, load it. @@ -717,9 +721,12 @@ void ScreenManager::LoadDelayedScreen() ASSERT( bLoaded ); } - if( deletePrepared ) + if( !apActorsToDelete.empty() ) { - DeletePreparedScreens(); + BeforeDeleteScreen(); + FOREACH( Actor*, apActorsToDelete, a ) + SAFE_DELETE( *a ); + AfterDeleteScreen(); } MESSAGEMAN->Broadcast( Message_ScreenChanged );