diff --git a/Dalamud/Interface/Internal/Windows/PluginImageCache.cs b/Dalamud/Interface/Internal/Windows/PluginImageCache.cs index df2aa5422..4614fbad2 100644 --- a/Dalamud/Interface/Internal/Windows/PluginImageCache.cs +++ b/Dalamud/Interface/Internal/Windows/PluginImageCache.cs @@ -45,6 +45,9 @@ internal class PluginImageCache : IDisposable, IServiceType private const string MainRepoImageUrl = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/api6/{0}/{1}/images/{2}"; private const string MainRepoDip17ImageUrl = "https://raw.githubusercontent.com/goatcorp/PluginDistD17/main/{0}/{1}/images/{2}"; + [ServiceManager.ServiceDependency] + private readonly InterfaceManager.InterfaceManagerWithScene imWithScene = Service.Get(); + private readonly BlockingCollection>> downloadQueue = new(); private readonly BlockingCollection> loadQueue = new(); private readonly CancellationTokenSource cancelToken = new(); @@ -68,9 +71,8 @@ internal class PluginImageCache : IDisposable, IServiceType [ServiceManager.ServiceConstructor] private PluginImageCache(Dalamud dalamud) { - var imwst = Service.GetAsync(); - Task? TaskWrapIfNonNull(TextureWrap? tw) => tw == null ? null : Task.FromResult(tw!); + var imwst = Task.Run(() => this.imWithScene); this.emptyTextureTask = imwst.ContinueWith(task => task.Result.Manager.LoadImageRaw(new byte[64], 8, 8, 4)!); this.defaultIconTask = imwst.ContinueWith(task => TaskWrapIfNonNull(task.Result.Manager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "defaultIcon.png"))) ?? this.emptyTextureTask).Unwrap(); @@ -297,7 +299,7 @@ internal class PluginImageCache : IDisposable, IServiceType return false; } - private static async Task TryLoadImage( + private async Task TryLoadImage( byte[]? bytes, string name, string? loc, @@ -309,7 +311,7 @@ internal class PluginImageCache : IDisposable, IServiceType if (bytes == null) return null; - var interfaceManager = (await Service.GetAsync()).Manager; + var interfaceManager = this.imWithScene.Manager; var framework = await Service.GetAsync(); TextureWrap? image; @@ -453,8 +455,6 @@ internal class PluginImageCache : IDisposable, IServiceType private async Task LoadTask(int concurrency) { - await Service.GetAsync(); - var token = this.cancelToken.Token; var runningTasks = new List(); while (true) @@ -500,7 +500,7 @@ internal class PluginImageCache : IDisposable, IServiceType () => File.ReadAllBytesAsync(file.FullName), requestedFrame); var fileIcon = await this.RunInLoadQueue( - () => TryLoadImage( + () => this.TryLoadImage( fileBytes, "icon", file.FullName, @@ -548,7 +548,7 @@ internal class PluginImageCache : IDisposable, IServiceType return null; var icon = await this.RunInLoadQueue( - () => TryLoadImage(bytes, "icon", url, manifest, PluginIconWidth, PluginIconHeight, true)); + () => this.TryLoadImage(bytes, "icon", url, manifest, PluginIconWidth, PluginIconHeight, true)); if (icon != null) Log.Verbose($"Plugin icon for {manifest.InternalName} loaded"); return icon; @@ -573,7 +573,7 @@ internal class PluginImageCache : IDisposable, IServiceType () => File.ReadAllBytesAsync(file.FullName), requestedFrame); var image = await this.RunInLoadQueue( - () => TryLoadImage( + () => this.TryLoadImage( bytes, $"image{i2 + 1}", file.FullName, @@ -639,7 +639,7 @@ internal class PluginImageCache : IDisposable, IServiceType if (bytes == null) return; - var image = await TryLoadImage( + var image = await this.TryLoadImage( bytes, $"image{i2 + 1}", "queue", diff --git a/Dalamud/Interface/Windowing/WindowSystem.cs b/Dalamud/Interface/Windowing/WindowSystem.cs index fbcc60df3..6c9789735 100644 --- a/Dalamud/Interface/Windowing/WindowSystem.cs +++ b/Dalamud/Interface/Windowing/WindowSystem.cs @@ -83,7 +83,7 @@ public class WindowSystem if (window is IDisposable disposable) disposable.Dispose(); - + this.windows.Remove(window); }