diff --git a/cocos/2d/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp index f9ab164096..90e5b99dc9 100644 --- a/cocos/2d/CCFontAtlasCache.cpp +++ b/cocos/2d/CCFontAtlasCache.cpp @@ -237,20 +237,19 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas *atlas) { if (nullptr != atlas) { - for( auto &item: _atlasMap ) + if (atlas->getReferenceCount() == 1) { - if ( item.second == atlas ) + for( auto &item: _atlasMap ) { - if (atlas->getReferenceCount() == 1) + if ( item.second == atlas ) { - _atlasMap.erase(item.first); + _atlasMap.erase(item.first); + break; } - - atlas->release(); - - return true; } - } + } + atlas->release(); + return true; } return false;