From d1291364e01ba7e031f611397eae84c1d32b64d5 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Tue, 23 Jan 2024 19:30:09 +0900 Subject: [PATCH] Fix FontHandleWrapper and some docs --- Dalamud/Interface/UiBuilder.cs | 22 +++++++++---------- .../Storage/Assets/IDalamudAssetManager.cs | 6 +++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index 1134704ee..d01d307c3 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -744,10 +744,12 @@ public sealed class UiBuilder : IDisposable public event Action? ImFontChanged; - public Exception? LoadException => - this.wrapped!.LoadException ?? new ObjectDisposedException(nameof(FontHandleWrapper)); + public Exception? LoadException => this.WrappedNotDisposed.LoadException; - public bool Available => this.wrapped?.Available ?? false; + public bool Available => this.WrappedNotDisposed.Available; + + private IFontHandle WrappedNotDisposed => + this.wrapped ?? throw new ObjectDisposedException(nameof(FontHandleWrapper)); public void Dispose() { @@ -759,19 +761,17 @@ public sealed class UiBuilder : IDisposable // Note: do not dispose w; we do not own it } - public IFontHandle.ImFontLocked Lock() => - this.wrapped?.Lock() ?? throw new ObjectDisposedException(nameof(FontHandleWrapper)); + public IFontHandle.ImFontLocked Lock() => this.WrappedNotDisposed.Lock(); - public IDisposable Push() => - this.wrapped?.Push() ?? throw new ObjectDisposedException(nameof(FontHandleWrapper)); + public IDisposable Push() => this.WrappedNotDisposed.Push(); - public void Pop() => this.wrapped?.Pop(); + public void Pop() => this.WrappedNotDisposed.Pop(); public Task WaitAsync() => - this.wrapped?.WaitAsync().ContinueWith(_ => (IFontHandle)this) ?? - throw new ObjectDisposedException(nameof(FontHandleWrapper)); + this.WrappedNotDisposed.WaitAsync().ContinueWith(_ => (IFontHandle)this); - public override string ToString() => $"{nameof(FontHandleWrapper)}({this.wrapped})"; + public override string ToString() => + $"{nameof(FontHandleWrapper)}({this.wrapped?.ToString() ?? "disposed"})"; private void WrappedOnImFontChanged(IFontHandle obj) => this.ImFontChanged.InvokeSafely(this); } diff --git a/Dalamud/Storage/Assets/IDalamudAssetManager.cs b/Dalamud/Storage/Assets/IDalamudAssetManager.cs index 4fb83df80..1202891b8 100644 --- a/Dalamud/Storage/Assets/IDalamudAssetManager.cs +++ b/Dalamud/Storage/Assets/IDalamudAssetManager.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.Contracts; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; using System.IO; using System.Threading.Tasks; @@ -64,8 +65,9 @@ internal interface IDalamudAssetManager /// /// The texture asset. /// The default return value, if the asset is not ready for whatever reason. - /// The texture wrap. + /// The texture wrap. Can be null only if is null. [Pure] + [return: NotNullIfNotNull(nameof(defaultWrap))] IDalamudTextureWrap? GetDalamudTextureWrap(DalamudAsset asset, IDalamudTextureWrap? defaultWrap); ///