diff --git a/Dalamud/Interface/GameFonts/GameFontManager.cs b/Dalamud/Interface/GameFonts/GameFontManager.cs index 48a1f7271..a7cd27b83 100644 --- a/Dalamud/Interface/GameFonts/GameFontManager.cs +++ b/Dalamud/Interface/GameFonts/GameFontManager.cs @@ -169,7 +169,7 @@ internal class GameFontManager : IServiceType } if (rebuildLookupTable && fontPtr.Glyphs.Size > 0) - fontPtr.BuildLookupTable(); + fontPtr.BuildLookupTableNonstandard(); } /// diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 72b3bd6c8..d5394fe8d 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -1028,7 +1028,7 @@ internal class InterfaceManager : IDisposable, IServiceType if (font.FindGlyphNoFallback(Fallback1Codepoint).NativePtr != null) font.FallbackChar = Fallback1Codepoint; - font.BuildLookupTable(); + font.BuildLookupTableNonstandard(); } Log.Verbose("[FONT] Invoke OnAfterBuildFonts"); diff --git a/Dalamud/Interface/Utility/ImGuiHelpers.cs b/Dalamud/Interface/Utility/ImGuiHelpers.cs index dbb873edf..010178b26 100644 --- a/Dalamud/Interface/Utility/ImGuiHelpers.cs +++ b/Dalamud/Interface/Utility/ImGuiHelpers.cs @@ -240,7 +240,25 @@ public static class ImGuiHelpers } if (rebuildLookupTable && target.Value!.Glyphs.Size > 0) - target.Value!.BuildLookupTable(); + target.Value!.BuildLookupTableNonstandard(); + } + + /// + /// Call ImFont::BuildLookupTable, after attempting to fulfill some preconditions. + /// + /// The font. + public static unsafe void BuildLookupTableNonstandard(this ImFontPtr font) + { + // ImGui resolves ' ' with FindGlyph, which uses FallbackGlyph. + // FallbackGlyph is resolved after resolving ' '. + // On the first call of BuildLookupTable, called from BuildFonts, FallbackGlyph is set to null, + // making FindGlyph return nullptr. + // On our secondary calls of BuildLookupTable, FallbackGlyph is set to some value that is not null, + // making ImGui attempt to treat whatever was there as a ' '. + // This may cause random glyphs to be sized randomly, if not an access violation exception. + font.NativePtr->FallbackGlyph = null; + + font.BuildLookupTable(); } ///