fix: explicitly declare InterfaceManagerWithScene as a dependency for PluginImageCache

This commit is contained in:
goat 2023-01-26 23:05:10 +01:00
parent 80bf56ab5b
commit 261d8a167f
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 11 additions and 11 deletions

View file

@ -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<InterfaceManager.InterfaceManagerWithScene>.Get();
private readonly BlockingCollection<Tuple<ulong, Func<Task>>> downloadQueue = new();
private readonly BlockingCollection<Func<Task>> 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<InterfaceManager.InterfaceManagerWithScene>.GetAsync();
Task<TextureWrap>? 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<TextureWrap?> TryLoadImage(
private async Task<TextureWrap?> 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<InterfaceManager.InterfaceManagerWithScene>.GetAsync()).Manager;
var interfaceManager = this.imWithScene.Manager;
var framework = await Service<Framework>.GetAsync();
TextureWrap? image;
@ -453,8 +455,6 @@ internal class PluginImageCache : IDisposable, IServiceType
private async Task LoadTask(int concurrency)
{
await Service<InterfaceManager.InterfaceManagerWithScene>.GetAsync();
var token = this.cancelToken.Token;
var runningTasks = new List<Task>();
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",

View file

@ -83,7 +83,7 @@ public class WindowSystem
if (window is IDisposable disposable)
disposable.Dispose();
this.windows.Remove(window);
}