Fix crash on shutdown in FGFontCache
Reported here by Michael: https://sourceforge.net/p/flightgear/codetickets/2114/
This commit is contained in:
parent
dce282d7b8
commit
1d97267663
2 changed files with 31 additions and 20 deletions
|
@ -94,10 +94,14 @@ FGFontCache::FGFontCache() :
|
|||
|
||||
FGFontCache::~FGFontCache()
|
||||
{
|
||||
PuFontMap::iterator it, end = _puFonts.end();
|
||||
for (it = _puFonts.begin(); it != end; ++it)
|
||||
delete it->second;
|
||||
_puFonts.clear();
|
||||
for (auto puFontIt : _cache) {
|
||||
delete puFontIt.second;
|
||||
}
|
||||
|
||||
// these were created i initializeFonts
|
||||
for (auto texFontIt : _texFonts) {
|
||||
delete texFontIt.second;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool FGFontCache::FntParamsLess::operator()(const FntParams& f1,
|
||||
|
@ -115,12 +119,12 @@ inline bool FGFontCache::FntParamsLess::operator()(const FntParams& f1,
|
|||
return f1.slant < f2.slant;
|
||||
}
|
||||
|
||||
struct FGFontCache::fnt *
|
||||
FGFontCache::FontCacheEntry*
|
||||
FGFontCache::getfnt(const std::string& fontName, float size, float slant)
|
||||
{
|
||||
FntParams fntParams(fontName, size, slant);
|
||||
PuFontMap::iterator i = _puFonts.find(fntParams);
|
||||
if (i != _puFonts.end())
|
||||
PuFontMap::iterator i = _cache.find(fntParams);
|
||||
if (i != _cache.end())
|
||||
return i->second;
|
||||
// fntTexFont s are all preloaded into the _texFonts map
|
||||
TexFontMap::iterator texi = _texFonts.find(fontName);
|
||||
|
@ -135,17 +139,21 @@ FGFontCache::getfnt(const std::string& fontName, float size, float slant)
|
|||
pufont = guifont->font;
|
||||
}
|
||||
}
|
||||
fnt* f = new fnt;
|
||||
|
||||
auto f = new FontCacheEntry;
|
||||
if (pufont) {
|
||||
f->pufont = pufont;
|
||||
} else if (texfont) {
|
||||
f->texfont = texfont;
|
||||
f->ownsPUFont = true; // ensure it gets cleaned up
|
||||
f->pufont = new puFont;
|
||||
f->pufont->initialize(static_cast<fntFont *>(f->texfont), size, slant);
|
||||
} else {
|
||||
f->pufont = guifonts[0].font;
|
||||
}
|
||||
_puFonts[fntParams] = f;
|
||||
|
||||
// insert into the cache
|
||||
_cache[fntParams] = f;
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -223,11 +231,10 @@ bool FGFontCache::initializeFonts()
|
|||
return true;
|
||||
}
|
||||
|
||||
FGFontCache::fnt::~fnt()
|
||||
FGFontCache::FontCacheEntry::~FontCacheEntry()
|
||||
{
|
||||
if (texfont) {
|
||||
delete pufont;
|
||||
delete texfont;
|
||||
if (ownsPUFont) {
|
||||
delete pufont;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,25 +54,29 @@ private:
|
|||
{
|
||||
bool operator() (const FntParams& f1, const FntParams& f2) const;
|
||||
};
|
||||
struct fnt {
|
||||
fnt(puFont *pu = 0) : pufont(pu), texfont(0) {}
|
||||
~fnt();
|
||||
|
||||
|
||||
struct FontCacheEntry {
|
||||
FontCacheEntry(puFont* pu = 0) : pufont(pu), texfont(0) {}
|
||||
~FontCacheEntry();
|
||||
|
||||
// Font used by plib GUI code
|
||||
puFont *pufont;
|
||||
// TXF font
|
||||
fntTexFont *texfont;
|
||||
|
||||
bool ownsPUFont = false;
|
||||
};
|
||||
|
||||
// Path to the font directory
|
||||
SGPath _path;
|
||||
|
||||
typedef std::map<const std::string, fntTexFont*> TexFontMap;
|
||||
typedef std::map<const FntParams, fnt*, FntParamsLess> PuFontMap;
|
||||
typedef std::map<const FntParams, FontCacheEntry*, FntParamsLess> PuFontMap;
|
||||
TexFontMap _texFonts;
|
||||
PuFontMap _puFonts;
|
||||
PuFontMap _cache;
|
||||
|
||||
bool _initialized;
|
||||
struct fnt *getfnt(const std::string& name, float size, float slant);
|
||||
FontCacheEntry* getfnt(const std::string& name, float size, float slant);
|
||||
void init();
|
||||
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue