correct usage of reference count of LabelAtlas (#18117)

This commit is contained in:
minggo 2017-07-31 09:05:55 +08:00 committed by GitHub
parent 3aa03b2fc6
commit 4be6eb5325
3 changed files with 7 additions and 25 deletions

View File

@ -42,6 +42,9 @@ void FontAtlasCache::purgeCachedData()
auto atlasMapCopy = _atlasMap;
for (auto&& atlas : atlasMapCopy)
{
auto refCount = atlas.second->getReferenceCount();
atlas.second->release();
if (refCount != 1)
atlas.second->purgeTexturesAtlas();
}
_atlasMap.clear();
@ -83,10 +86,7 @@ FontAtlas* FontAtlasCache::getFontAtlasTTF(const _ttfConfig* config)
}
}
else
{
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return nullptr;
}
@ -114,10 +114,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons
}
}
else
{
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return nullptr;
}
@ -142,10 +139,7 @@ FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
}
}
else
{
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return nullptr;
}
@ -172,10 +166,7 @@ FontAtlas* FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth
}
}
else
{
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return nullptr;
}
@ -202,10 +193,7 @@ FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, i
}
}
else
{
_atlasMap[atlasName]->retain();
return _atlasMap[atlasName];
}
return nullptr;
}

View File

@ -219,7 +219,7 @@ FontAtlas * FontFreeType::createFontAtlas()
_fontAtlas->prepareLetterDefinitions(utf32);
}
}
this->autorelease();
// this->autorelease();
}
return _fontAtlas;

View File

@ -588,22 +588,16 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
}
if (atlas == _fontAtlas)
{
if (_fontAtlas)
{
FontAtlasCache::releaseFontAtlas(_fontAtlas);
}
return;
}
CC_SAFE_RETAIN(atlas);
if (_fontAtlas)
{
_batchNodes.clear();
FontAtlasCache::releaseFontAtlas(_fontAtlas);
_fontAtlas = nullptr;
}
_fontAtlas = atlas;
if (_reusedLetter == nullptr)
{
_reusedLetter = Sprite::create();