diff --git a/HellionChat/FontManager.cs b/HellionChat/FontManager.cs index 6a86efa..17daf5d 100644 --- a/HellionChat/FontManager.cs +++ b/HellionChat/FontManager.cs @@ -44,16 +44,26 @@ public class FontManager // Hellion font bytes (Exo 2, OFL-1.1); lazily loaded from manifest resources private static byte[]? HellionFontBytes; - private static byte[] GetHellionFontBytes() + // Returns null when the embedded font resource is missing. Should never + // happen on a signed release build, but a broken csproj or hand-rolled + // dev build can land here. Caller falls back to the system font path so + // the plugin still loads instead of crashing the whole UiBuilder. + private static byte[]? TryGetHellionFontBytes() { if (HellionFontBytes is not null) return HellionFontBytes; - using var stream = - typeof(FontManager).Assembly.GetManifestResourceStream("HellionFont.ttf") - ?? throw new FileNotFoundException( - "Hellion font resource not embedded in the assembly" + using var stream = typeof(FontManager).Assembly.GetManifestResourceStream( + "HellionFont.ttf" + ); + if (stream is null) + { + Plugin.Log.Warning( + "Hellion font resource missing — falling back to system default font." ); + return null; + } + using var ms = new MemoryStream(); stream.CopyTo(ms); HellionFontBytes = ms.ToArray(); @@ -146,8 +156,11 @@ public class FontManager ? Plugin.Config.FontSizeV2 : Plugin.Config.GlobalFontV2.SizePt; var config = new SafeFontConfig { SizePt = basePt, GlyphRanges = Ranges }; - config.MergeFont = Plugin.Config.UseHellionFont - ? tk.AddFontFromMemory(GetHellionFontBytes(), config, "Hellion-Exo2") + // F10.2: if the embedded font is missing, drop to the system font + // path rather than letting the UiBuilder throw. + var hellionBytes = Plugin.Config.UseHellionFont ? TryGetHellionFontBytes() : null; + config.MergeFont = hellionBytes is not null + ? tk.AddFontFromMemory(hellionBytes, config, "Hellion-Exo2") : AddFontWithFallback(tk, Plugin.Config.GlobalFontV2.FontId, config, "global"); config.SizePt = Plugin.Config.JapaneseFontV2.SizePt;