Fonts: Fixed crash when manually specifying an EllipsisChar that doesn't exist. (#6480)
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 2532c81..fa07889 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -73,6 +73,7 @@
- Menus: Fixed an issue when opening a menu hierarchy in a given menu-bar would allow
opening another via simple hovering. (#3496, #4797)
- Fonts: Fixed crash when merging fonts and the first font has no valid glyph. (#6446) [@JaedanC]
+- Fonts: Fixed crash when manually specifying an EllipsisChar that doesn't exist. (#6480)
- Misc: Added ImVec2 unary minus operator. (#6368) [@Koostosh]
- Debug Tools: Debug Log: Fixed not parsing 0xXXXXXXXX values for geo-locating on mouse
hover hover when the identifier is at the end of the line. (#5855)
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index 05db22f..0a008c0 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -3200,7 +3200,25 @@
SetGlyphVisible((ImWchar)' ', false);
SetGlyphVisible((ImWchar)'\t', false);
- // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
+ // Setup Fallback character
+ const ImWchar fallback_chars[] = { (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' };
+ FallbackGlyph = FindGlyphNoFallback(FallbackChar);
+ if (FallbackGlyph == NULL)
+ {
+ FallbackChar = FindFirstExistingGlyph(this, fallback_chars, IM_ARRAYSIZE(fallback_chars));
+ FallbackGlyph = FindGlyphNoFallback(FallbackChar);
+ if (FallbackGlyph == NULL)
+ {
+ FallbackGlyph = &Glyphs.back();
+ FallbackChar = (ImWchar)FallbackGlyph->Codepoint;
+ }
+ }
+ FallbackAdvanceX = FallbackGlyph->AdvanceX;
+ for (int i = 0; i < max_codepoint + 1; i++)
+ if (IndexAdvanceX[i] < 0.0f)
+ IndexAdvanceX[i] = FallbackAdvanceX;
+
+ // Setup Ellipsis character. It is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
// However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
// FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots.
const ImWchar ellipsis_chars[] = { (ImWchar)0x2026, (ImWchar)0x0085 };
@@ -3221,25 +3239,6 @@
EllipsisCharStep = (glyph->X1 - glyph->X0) + 1.0f;
EllipsisWidth = EllipsisCharStep * 3.0f - 1.0f;
}
-
- // Setup fallback character
- const ImWchar fallback_chars[] = { (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' };
- FallbackGlyph = FindGlyphNoFallback(FallbackChar);
- if (FallbackGlyph == NULL)
- {
- FallbackChar = FindFirstExistingGlyph(this, fallback_chars, IM_ARRAYSIZE(fallback_chars));
- FallbackGlyph = FindGlyphNoFallback(FallbackChar);
- if (FallbackGlyph == NULL)
- {
- FallbackGlyph = &Glyphs.back();
- FallbackChar = (ImWchar)FallbackGlyph->Codepoint;
- }
- }
-
- FallbackAdvanceX = FallbackGlyph->AdvanceX;
- for (int i = 0; i < max_codepoint + 1; i++)
- if (IndexAdvanceX[i] < 0.0f)
- IndexAdvanceX[i] = FallbackAdvanceX;
}
// API is designed this way to avoid exposing the 4K page size