From d98708e9a8fd5079fdb0e68e05e21fa0c97c74b7 Mon Sep 17 00:00:00 2001 From: goat Date: Mon, 15 Apr 2024 00:44:51 +0200 Subject: [PATCH] fix fixed-width icon font build error, show error message if fonts fail to build --- .../Interface/Internal/InterfaceManager.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 0e28c1025..62506c331 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -17,12 +17,12 @@ using Dalamud.Hooking; using Dalamud.Hooking.WndProcHook; using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.Internal.ManagedAsserts; -using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.Style; using Dalamud.Interface.Utility; using Dalamud.Interface.Windowing; +using Dalamud.Logging.Internal; using Dalamud.Utility; using Dalamud.Utility.Timing; @@ -32,8 +32,6 @@ using ImGuiScene; using PInvoke; -using Serilog; - using SharpDX; using SharpDX.Direct3D; using SharpDX.Direct3D11; @@ -69,6 +67,8 @@ internal class InterfaceManager : IInternalDisposableService /// public const float DefaultFontSizePx = (DefaultFontSizePt * 4.0f) / 3.0f; + private static readonly ModuleLog Log = new("INTERFACE"); + private readonly ConcurrentBag deferredDisposeTextures = new(); private readonly ConcurrentBag deferredDisposeImFontLockeds = new(); @@ -686,7 +686,16 @@ internal class InterfaceManager : IInternalDisposableService Debug.Assert(this.scene is not null, "InitScene did not set the scene field, but did not throw an exception."); if (!this.dalamudAtlas!.HasBuiltAtlas) + { + if (this.dalamudAtlas.BuildTask.Exception != null) + { + // TODO: Can we do something more user-friendly here? Unload instead? + Util.Fatal("Failed to initialize Dalamud base fonts.\nPlease report this error.", "Dalamud"); + Log.Error(this.dalamudAtlas.BuildTask.Exception, "Failed to initialize Dalamud base fonts"); + } + return this.presentHook!.Original(swapChain, syncInterval, presentFlags); + } if (this.address.IsReshade) { @@ -738,6 +747,7 @@ internal class InterfaceManager : IInternalDisposableService .CreateFontAtlas(nameof(InterfaceManager), FontAtlasAutoRebuildMode.Disable); using (this.dalamudAtlas.SuppressAutoRebuild()) { + var defaultSizePx = Service.Get().DefaultFontSpec.SizePx; this.DefaultFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( e => e.OnPreBuild(tk => tk.AddDalamudDefaultFont(-1))); this.IconFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( @@ -745,7 +755,7 @@ internal class InterfaceManager : IInternalDisposableService tk => tk.AddFontAwesomeIconFont( new() { - SizePx = Service.Get().DefaultFontSpec.SizePx, + SizePx = defaultSizePx, GlyphMinAdvanceX = DefaultFontSizePx, GlyphMaxAdvanceX = DefaultFontSizePx, }))); @@ -754,7 +764,8 @@ internal class InterfaceManager : IInternalDisposableService DalamudAsset.FontAwesomeFreeSolid, new() { - GlyphRanges = new ushort[] { 0x20 }, + SizePx = defaultSizePx, + GlyphRanges = new ushort[] { 0x20, 0x20, 0x00 }, }))); this.MonoFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( e => e.OnPreBuild( @@ -762,7 +773,7 @@ internal class InterfaceManager : IInternalDisposableService DalamudAsset.InconsolataRegular, new() { - SizePx = Service.Get().DefaultFontSpec.SizePx, + SizePx = defaultSizePx, }))); this.dalamudAtlas.BuildStepChange += e => e.OnPostBuild( tk => @@ -801,7 +812,7 @@ internal class InterfaceManager : IInternalDisposableService }); }; } - + // This will wait for scene on its own. We just wait for this.dalamudAtlas.BuildTask in this.InitScene. _ = this.dalamudAtlas.BuildFontsAsync();