Skip to content

Commit 2675f1d

Browse files
sbrednikhinminggo
authored and
minggo
committed
Font atlas texture initialization delayed (#19384)
If you will try to create CCLabel with True Type font, enabling it's outline and change it's font size with separate commands you will create multiple textures for font atlases, one for label second for label with outline, and third for label with another font size. Moving texture initialization from constructor and calling it later, right before usage will cause large memory economy, because even if atlases will be created they won't create textures of allocate memory for current page data.
1 parent 17704df commit 2675f1d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cocos/2d/CCFontAtlas.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ FontAtlas::FontAtlas(Font &theFont)
7171
{
7272
_letterPadding += 2 * FontFreeType::DistanceMapSpread;
7373
}
74-
75-
reinit();
7674

7775
#if CC_ENABLE_CACHE_TEXTURE_DATA
7876
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
@@ -343,7 +341,10 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
343341
{
344342
return false;
345343
}
346-
344+
345+
if (!_currentPageData)
346+
reinit();
347+
347348
std::unordered_map<unsigned int, unsigned int> codeMapOfNewChar;
348349
findNewCharacters(utf32Text, codeMapOfNewChar);
349350
if (codeMapOfNewChar.empty())

0 commit comments

Comments
 (0)