diff --git a/Dalamud/Interface/Internal/SharableTextures/FileSystemSharableTexture.cs b/Dalamud/Interface/Internal/SharableTextures/FileSystemSharableTexture.cs index ff4a6adbf..bd867d6a3 100644 --- a/Dalamud/Interface/Internal/SharableTextures/FileSystemSharableTexture.cs +++ b/Dalamud/Interface/Internal/SharableTextures/FileSystemSharableTexture.cs @@ -23,12 +23,7 @@ internal sealed class FileSystemSharableTexture : SharableTexture { this.path = path; if (holdSelfReference) - { - this.UnderlyingWrap = Service.Get().CreateLoader( - this, - this.CreateTextureAsync, - this.LoadCancellationToken); - } + this.ReviveResources(); } /// diff --git a/Dalamud/Interface/Internal/SharableTextures/GamePathSharableTexture.cs b/Dalamud/Interface/Internal/SharableTextures/GamePathSharableTexture.cs index ad026aff7..82f2d1b48 100644 --- a/Dalamud/Interface/Internal/SharableTextures/GamePathSharableTexture.cs +++ b/Dalamud/Interface/Internal/SharableTextures/GamePathSharableTexture.cs @@ -27,12 +27,7 @@ internal sealed class GamePathSharableTexture : SharableTexture { this.path = path; if (holdSelfReference) - { - this.UnderlyingWrap = Service.Get().CreateLoader( - this, - this.CreateTextureAsync, - this.LoadCancellationToken); - } + this.ReviveResources(); } /// diff --git a/Dalamud/Interface/Internal/SharableTextures/SharableTexture.cs b/Dalamud/Interface/Internal/SharableTextures/SharableTexture.cs index 0a5faffc2..0bdd4ed4a 100644 --- a/Dalamud/Interface/Internal/SharableTextures/SharableTexture.cs +++ b/Dalamud/Interface/Internal/SharableTextures/SharableTexture.cs @@ -32,14 +32,26 @@ internal abstract class SharableTexture : IRefCountable, TextureLoadThrottler.IT protected SharableTexture(bool holdSelfReference) { this.InstanceIdForDebug = Interlocked.Increment(ref instanceCounter); - this.refCount = 1; - this.selfReferenceExpiry = - holdSelfReference - ? Environment.TickCount64 + SelfReferenceDurationTicks - : SelfReferenceExpiryExpired; - this.IsOpportunistic = true; + + if (holdSelfReference) + { + this.refCount = 1; + this.selfReferenceExpiry = Environment.TickCount64 + SelfReferenceDurationTicks; + this.ContentQueried = true; + this.IsOpportunistic = true; + this.resourceReleased = false; + this.cancellationTokenSource = new(); + } + else + { + this.refCount = 0; + this.selfReferenceExpiry = SelfReferenceExpiryExpired; + this.ContentQueried = false; + this.IsOpportunistic = false; + this.resourceReleased = true; + } + this.FirstRequestedTick = this.LatestRequestedTick = Environment.TickCount64; - this.cancellationTokenSource = new(); } /// @@ -84,6 +96,12 @@ internal abstract class SharableTexture : IRefCountable, TextureLoadThrottler.IT /// public long LatestRequestedTick { get; private set; } + /// + /// Gets a value indicating whether the content has been queried, + /// i.e. or is called. + /// + public bool ContentQueried { get; private set; } + /// /// Gets or sets the dispose-suppressing wrap for . /// @@ -199,8 +217,12 @@ internal abstract class SharableTexture : IRefCountable, TextureLoadThrottler.IT public IDalamudTextureWrap? GetImmediate() { if (this.TryAddRef(out _) != IRefCountable.RefCountResult.StillAlive) + { + this.ContentQueried = true; return null; + } + this.ContentQueried = true; this.LatestRequestedTick = Environment.TickCount64; var nexp = Environment.TickCount64 + SelfReferenceDurationTicks; while (true) @@ -230,7 +252,15 @@ internal abstract class SharableTexture : IRefCountable, TextureLoadThrottler.IT { cancellationToken.ThrowIfCancellationRequested(); - this.AddRef(); + try + { + this.AddRef(); + } + finally + { + this.ContentQueried = true; + } + if (this.UnderlyingWrap is null) throw new InvalidOperationException("AddRef returned but UnderlyingWrap is null?"); diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index 0e6686025..7789e9e76 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -469,7 +469,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid return; static bool TextureFinalReleasePredicate(SharableTexture v) => - v.ReleaseSelfReference(false) == 0 && !v.HasRevivalPossibility; + v.ContentQueried && v.ReleaseSelfReference(false) == 0 && !v.HasRevivalPossibility; } private string GetIconPathByValue(GameIconLookup lookup) =>