fixed #16652: FontFreeType crashes in its destructor. (#16684)

This commit is contained in:
James Chen 2016-10-14 17:49:36 +08:00 committed by minggo
parent 58414f85a1
commit 627eba6aac
1 changed files with 8 additions and 4 deletions

View File

@ -51,7 +51,7 @@ static std::unordered_map<std::string, DataRef> s_cacheFontData;
FontFreeType * FontFreeType::create(const std::string &fontName, float fontSize, GlyphCollection glyphs, const char *customGlyphs,bool distanceFieldEnabled /* = false */,int outline /* = 0 */)
{
FontFreeType *tempFont = new FontFreeType(distanceFieldEnabled,outline);
FontFreeType *tempFont = new (std::nothrow) FontFreeType(distanceFieldEnabled,outline);
if (!tempFont)
return nullptr;
@ -195,10 +195,14 @@ FontFreeType::~FontFreeType()
}
}
s_cacheFontData[_fontName].referenceCount -= 1;
if (s_cacheFontData[_fontName].referenceCount == 0)
auto iter = s_cacheFontData.find(_fontName);
if (iter != s_cacheFontData.end())
{
s_cacheFontData.erase(_fontName);
iter->second.referenceCount -= 1;
if (iter->second.referenceCount == 0)
{
s_cacheFontData.erase(iter);
}
}
}