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

View File

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

View File

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