Skip to content

Commit 12303e2

Browse files
committed
#3347 Crashes in LLFontFreetype::renderGlyph
Try to handle this more gracefully, but primary purpose of this change is to log wchars in case issue is reproducible.
1 parent edebc8f commit 12303e2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

indra/llrender/llfontfreetype.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l
552552
return NULL;
553553

554554
llassert(!mIsFallback);
555-
fontp->renderGlyph(requested_glyph_type, glyph_index);
555+
fontp->renderGlyph(requested_glyph_type, glyph_index, wch);
556556

557557
EFontGlyphType bitmap_glyph_type = EFontGlyphType::Unspecified;
558558
switch (fontp->mFTFace->glyph->bitmap.pixel_mode)
@@ -697,7 +697,7 @@ void LLFontFreetype::insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const
697697
}
698698
}
699699

700-
void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index) const
700+
void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, llwchar wch) const
701701
{
702702
if (mFTFace == NULL)
703703
return;
@@ -712,11 +712,28 @@ void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index) co
712712
FT_Error error = FT_Load_Glyph(mFTFace, glyph_index, load_flags);
713713
if (FT_Err_Ok != error)
714714
{
715+
if (error == FT_Err_Out_Of_Memory)
716+
{
717+
LLError::LLUserWarningMsg::showOutOfMemory();
718+
LL_ERRS() << "Out of memory loading glyph for character " << wch << LL_ENDL;
719+
}
720+
715721
std::string message = llformat(
716-
"Error %d (%s) loading glyph %u: bitmap_type=%u, load_flags=%d",
717-
error, FT_Error_String(error), glyph_index, bitmap_type, load_flags);
722+
"Error %d (%s) loading wchar %u glyph %u/%u: bitmap_type=%u, load_flags=%d",
723+
error, FT_Error_String(error), wch, glyph_index, mFTFace->num_glyphs, bitmap_type, load_flags);
718724
LL_WARNS_ONCE() << message << LL_ENDL;
719725
error = FT_Load_Glyph(mFTFace, glyph_index, load_flags ^ FT_LOAD_COLOR);
726+
if (FT_Err_Invalid_Outline == error
727+
|| FT_Err_Invalid_Composite == error
728+
|| (FT_Err_Ok != error && LLStringOps::isEmoji(wch)))
729+
{
730+
glyph_index = FT_Get_Char_Index(mFTFace, '?');
731+
// if '?' is not present, potentially can use last index, that's supposed to be null glyph
732+
if (glyph_index > 0)
733+
{
734+
error = FT_Load_Glyph(mFTFace, glyph_index, load_flags ^ FT_LOAD_COLOR);
735+
}
736+
}
720737
llassert_always_msg(FT_Err_Ok == error, message.c_str());
721738
}
722739

indra/llrender/llfontfreetype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class LLFontFreetype : public LLRefCount
156156
bool hasGlyph(llwchar wch) const; // Has a glyph for this character
157157
LLFontGlyphInfo* addGlyph(llwchar wch, EFontGlyphType glyph_type) const; // Add a new character to the font if necessary
158158
LLFontGlyphInfo* addGlyphFromFont(const LLFontFreetype *fontp, llwchar wch, U32 glyph_index, EFontGlyphType bitmap_type) const; // Add a glyph from this font to the other (returns the glyph_index, 0 if not found)
159-
void renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index) const;
159+
void renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, llwchar wch) const;
160160
void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const;
161161

162162
std::string mName;

0 commit comments

Comments
 (0)