fix fixed-width icon font build error, show error message if fonts fail to build

This commit is contained in:
goat 2024-04-15 00:44:51 +02:00
parent 12efd9e679
commit d98708e9a8

View file

@ -17,12 +17,12 @@ using Dalamud.Hooking;
using Dalamud.Hooking.WndProcHook; using Dalamud.Hooking.WndProcHook;
using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Interface.Internal.ManagedAsserts; using Dalamud.Interface.Internal.ManagedAsserts;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.ManagedFontAtlas.Internals; using Dalamud.Interface.ManagedFontAtlas.Internals;
using Dalamud.Interface.Style; using Dalamud.Interface.Style;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Logging.Internal;
using Dalamud.Utility; using Dalamud.Utility;
using Dalamud.Utility.Timing; using Dalamud.Utility.Timing;
@ -32,8 +32,6 @@ using ImGuiScene;
using PInvoke; using PInvoke;
using Serilog;
using SharpDX; using SharpDX;
using SharpDX.Direct3D; using SharpDX.Direct3D;
using SharpDX.Direct3D11; using SharpDX.Direct3D11;
@ -69,6 +67,8 @@ internal class InterfaceManager : IInternalDisposableService
/// </summary> /// </summary>
public const float DefaultFontSizePx = (DefaultFontSizePt * 4.0f) / 3.0f; public const float DefaultFontSizePx = (DefaultFontSizePt * 4.0f) / 3.0f;
private static readonly ModuleLog Log = new("INTERFACE");
private readonly ConcurrentBag<IDeferredDisposable> deferredDisposeTextures = new(); private readonly ConcurrentBag<IDeferredDisposable> deferredDisposeTextures = new();
private readonly ConcurrentBag<ILockedImFont> deferredDisposeImFontLockeds = new(); private readonly ConcurrentBag<ILockedImFont> 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."); 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!.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); return this.presentHook!.Original(swapChain, syncInterval, presentFlags);
}
if (this.address.IsReshade) if (this.address.IsReshade)
{ {
@ -738,6 +747,7 @@ internal class InterfaceManager : IInternalDisposableService
.CreateFontAtlas(nameof(InterfaceManager), FontAtlasAutoRebuildMode.Disable); .CreateFontAtlas(nameof(InterfaceManager), FontAtlasAutoRebuildMode.Disable);
using (this.dalamudAtlas.SuppressAutoRebuild()) using (this.dalamudAtlas.SuppressAutoRebuild())
{ {
var defaultSizePx = Service<FontAtlasFactory>.Get().DefaultFontSpec.SizePx;
this.DefaultFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( this.DefaultFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle(
e => e.OnPreBuild(tk => tk.AddDalamudDefaultFont(-1))); e => e.OnPreBuild(tk => tk.AddDalamudDefaultFont(-1)));
this.IconFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( this.IconFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle(
@ -745,7 +755,7 @@ internal class InterfaceManager : IInternalDisposableService
tk => tk.AddFontAwesomeIconFont( tk => tk.AddFontAwesomeIconFont(
new() new()
{ {
SizePx = Service<FontAtlasFactory>.Get().DefaultFontSpec.SizePx, SizePx = defaultSizePx,
GlyphMinAdvanceX = DefaultFontSizePx, GlyphMinAdvanceX = DefaultFontSizePx,
GlyphMaxAdvanceX = DefaultFontSizePx, GlyphMaxAdvanceX = DefaultFontSizePx,
}))); })));
@ -754,7 +764,8 @@ internal class InterfaceManager : IInternalDisposableService
DalamudAsset.FontAwesomeFreeSolid, DalamudAsset.FontAwesomeFreeSolid,
new() new()
{ {
GlyphRanges = new ushort[] { 0x20 }, SizePx = defaultSizePx,
GlyphRanges = new ushort[] { 0x20, 0x20, 0x00 },
}))); })));
this.MonoFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle( this.MonoFontHandle = (FontHandle)this.dalamudAtlas.NewDelegateFontHandle(
e => e.OnPreBuild( e => e.OnPreBuild(
@ -762,7 +773,7 @@ internal class InterfaceManager : IInternalDisposableService
DalamudAsset.InconsolataRegular, DalamudAsset.InconsolataRegular,
new() new()
{ {
SizePx = Service<FontAtlasFactory>.Get().DefaultFontSpec.SizePx, SizePx = defaultSizePx,
}))); })));
this.dalamudAtlas.BuildStepChange += e => e.OnPostBuild( this.dalamudAtlas.BuildStepChange += e => e.OnPostBuild(
tk => 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 will wait for scene on its own. We just wait for this.dalamudAtlas.BuildTask in this.InitScene.
_ = this.dalamudAtlas.BuildFontsAsync(); _ = this.dalamudAtlas.BuildFontsAsync();