From 59bbaaaaa8a1796ca851e6d39c95b270574eb38c Mon Sep 17 00:00:00 2001 From: Aaron Barrett Date: Wed, 3 Nov 2021 20:21:11 -0700 Subject: [PATCH 1/2] Fixed the comparison statement in the first `for` loop in `DimensionsOfLine`. Previously, there was an intermittent crash in this method that happened when `deleteGlyphArray` got called, which called `FT_Done_Glyph` on glyphs that hadn't been initialized. They weren't initialized because the `for` loop ended before `maxGlyphs`... since `u8_nextchar` incremented `n` by a value greater than 1 when it encountered multi-byte characters. --- src/moaicore/MOAIFreeTypeFont.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/moaicore/MOAIFreeTypeFont.cpp b/src/moaicore/MOAIFreeTypeFont.cpp index 0acca160fe..205a9f62ca 100644 --- a/src/moaicore/MOAIFreeTypeFont.cpp +++ b/src/moaicore/MOAIFreeTypeFont.cpp @@ -590,7 +590,7 @@ USRect MOAIFreeTypeFont::DimensionsOfLine(cc8 *text, float fontSize, FT_Vector * // Gather up the positions of each glyph FT_Int penX = 0, penY = 0; - for (size_t n = 0; n < maxGlyphs; ) { + for (size_t n = 0; numGlyphs < maxGlyphs; numGlyphs++) { FT_UInt glyphIndex; int idx = (int)n; @@ -625,7 +625,6 @@ USRect MOAIFreeTypeFont::DimensionsOfLine(cc8 *text, float fontSize, FT_Vector * penX += glyphXAdvance; previousGlyphIndex = glyphIndex; - numGlyphs++; } // compute the bounding box of the glyphs From 1b9a28349d2350781defce0d53d9ae0dc2e7e6a9 Mon Sep 17 00:00:00 2001 From: Aaron Barrett Date: Wed, 3 Nov 2021 20:25:37 -0700 Subject: [PATCH 2/2] Switched the way that `maxGlyphs` gets calculated in `RenderTextureSingleLine` to use `glyphsInText` instead of `strlen`. `strlen` did not properly count multi-byte characters, which sometimes led to extra glyphs getting rendered at the end of a line. --- src/moaicore/MOAIFreeTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moaicore/MOAIFreeTypeFont.cpp b/src/moaicore/MOAIFreeTypeFont.cpp index 205a9f62ca..7ad862871e 100644 --- a/src/moaicore/MOAIFreeTypeFont.cpp +++ b/src/moaicore/MOAIFreeTypeFont.cpp @@ -1649,7 +1649,7 @@ MOAITexture* MOAIFreeTypeFont::RenderTextureSingleLine(cc8 *text, float fontSize FT_UInt numGlyphs; FT_Error error; - const size_t maxGlyphs = strlen(text); + const size_t maxGlyphs = glyphsInText(text); FT_Int maxDescender; FT_Int maxAscender;