From 9b2b3de565fb8d3a29382ea6154a5fa473d7a159 Mon Sep 17 00:00:00 2001 From: rh101 Date: Fri, 29 Oct 2021 00:07:46 +1100 Subject: [PATCH] The releaseFontAtlas method will remove the font atlas from the cache if it has a reference count of 1, and will always call release on that atlas as expected by the calling code. --- cocos/2d/CCFontAtlasCache.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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;