Merge pull request #6046 from Dhilan007/develop_label

Fixed possible crash if invoking FontAtlasCache::purgeCachedData.
This commit is contained in:
James Chen 2014-03-28 17:23:24 +08:00
commit 9836f11543
1 changed files with 52 additions and 52 deletions

View File

@ -59,91 +59,91 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const TTFConfig & config)
fontSize = Label::DistanceFieldFontSize / contentScaleFactor;
}
std::string atlasName = generateFontName(config.fontFilePath, fontSize, GlyphCollection::DYNAMIC, useDistanceField);
auto atlasName = generateFontName(config.fontFilePath, fontSize, GlyphCollection::DYNAMIC, useDistanceField);
atlasName.append("_outline_");
std::stringstream ss;
ss << config.outlineSize;
atlasName.append(ss.str());
FontAtlas *tempAtlas = _atlasMap[atlasName];
auto it = _atlasMap.find(atlasName);
if ( !tempAtlas )
if ( it == _atlasMap.end() )
{
FontFreeType *font = FontFreeType::create(config.fontFilePath, fontSize * contentScaleFactor, config.glyphs,
auto font = FontFreeType::create(config.fontFilePath, fontSize * contentScaleFactor, config.glyphs,
config.customGlyphs,useDistanceField,config.outlineSize * contentScaleFactor);
if (font)
{
tempAtlas = font->createFontAtlas();
auto tempAtlas = font->createFontAtlas();
if (tempAtlas)
{
_atlasMap[atlasName] = tempAtlas;
}
else
{
return nullptr;
return _atlasMap[atlasName];
}
}
}
else
{
tempAtlas->retain();
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return tempAtlas;
return nullptr;
}
FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, const Point& imageOffset /* = Point::ZERO */)
{
std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM,false);
FontAtlas *tempAtlas = _atlasMap[atlasName];
if ( !tempAtlas )
auto it = _atlasMap.find(atlasName);
if ( it == _atlasMap.end() )
{
Font *font = FontFNT::create(fontFileName,imageOffset);
auto font = FontFNT::create(fontFileName,imageOffset);
if(font)
{
tempAtlas = font->createFontAtlas();
auto tempAtlas = font->createFontAtlas();
if (tempAtlas)
{
_atlasMap[atlasName] = tempAtlas;
}
else
{
return nullptr;
return _atlasMap[atlasName];
}
}
}
else
{
tempAtlas->retain();
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return tempAtlas;
return nullptr;
}
FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
{
std::string atlasName = generateFontName(plistFile, 0, GlyphCollection::CUSTOM,false);
FontAtlas *tempAtlas = _atlasMap[atlasName];
auto it = _atlasMap.find(atlasName);
if ( !tempAtlas )
if ( it == _atlasMap.end() )
{
Font *font = FontCharMap::create(plistFile);
auto font = FontCharMap::create(plistFile);
if(font)
{
tempAtlas = font->createFontAtlas();
auto tempAtlas = font->createFontAtlas();
if (tempAtlas)
{
_atlasMap[atlasName] = tempAtlas;
}
else
{
return nullptr;
return _atlasMap[atlasName];
}
}
}
else
{
tempAtlas->retain();
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return tempAtlas;
return nullptr;
}
FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)
@ -151,57 +151,57 @@ FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidt
char tmp[30];
sprintf(tmp,"name:%u_%d_%d_%d",texture->getName(),itemWidth,itemHeight,startCharMap);
std::string atlasName = generateFontName(tmp, 0, GlyphCollection::CUSTOM,false);
FontAtlas *tempAtlas = _atlasMap[atlasName];
if ( !tempAtlas )
auto it = _atlasMap.find(atlasName);
if ( it == _atlasMap.end() )
{
Font *font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap);
auto font = FontCharMap::create(texture,itemWidth,itemHeight,startCharMap);
if(font)
{
tempAtlas = font->createFontAtlas();
auto tempAtlas = font->createFontAtlas();
if (tempAtlas)
{
_atlasMap[atlasName] = tempAtlas;
}
else
{
return nullptr;
return _atlasMap[atlasName];
}
}
}
else
{
tempAtlas->retain();
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return tempAtlas;
return nullptr;
}
FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
{
std::string atlasName = generateFontName(charMapFile, 0, GlyphCollection::CUSTOM,false);
FontAtlas *tempAtlas = _atlasMap[atlasName];
if ( !tempAtlas )
auto it = _atlasMap.find(atlasName);
if ( it == _atlasMap.end() )
{
Font *font = FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap);
auto font = FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap);
if(font)
{
tempAtlas = font->createFontAtlas();
auto tempAtlas = font->createFontAtlas();
if (tempAtlas)
{
_atlasMap[atlasName] = tempAtlas;
}
else
{
return nullptr;
return _atlasMap[atlasName];
}
}
}
else
{
tempAtlas->retain();
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return tempAtlas;
return nullptr;
}
std::string FontAtlasCache::generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField)