mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: load images on framework thread? maybe?
This commit is contained in:
parent
0fdacadc84
commit
095e7c3037
1 changed files with 59 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Game;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
@ -44,6 +44,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
private const string MainRepoImageUrl = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/api5/{0}/{1}/images/{2}";
|
private const string MainRepoImageUrl = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/api5/{0}/{1}/images/{2}";
|
||||||
|
|
||||||
private BlockingCollection<Func<Task>> downloadQueue = new();
|
private BlockingCollection<Func<Task>> downloadQueue = new();
|
||||||
|
private BlockingCollection<Action> loadQueue = new();
|
||||||
private CancellationTokenSource downloadToken = new();
|
private CancellationTokenSource downloadToken = new();
|
||||||
private Thread downloadThread;
|
private Thread downloadThread;
|
||||||
|
|
||||||
|
|
@ -74,6 +75,24 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
this.downloadThread = new Thread(this.DownloadTask);
|
this.downloadThread = new Thread(this.DownloadTask);
|
||||||
this.downloadThread.Start();
|
this.downloadThread.Start();
|
||||||
|
|
||||||
|
var framework = Service<Framework>.Get();
|
||||||
|
framework.Update += this.FrameworkOnUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FrameworkOnUpdate(Framework framework)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!this.loadQueue.TryTake(out var loadAction, 0, this.downloadToken.Token))
|
||||||
|
return;
|
||||||
|
|
||||||
|
loadAction.Invoke();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "An unhandled exception occurred in image loader framework dispatcher");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -114,6 +133,9 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
var framework = Service<Framework>.Get();
|
||||||
|
framework.Update -= this.FrameworkOnUpdate;
|
||||||
|
|
||||||
this.DefaultIcon?.Dispose();
|
this.DefaultIcon?.Dispose();
|
||||||
this.TroubleIcon?.Dispose();
|
this.TroubleIcon?.Dispose();
|
||||||
this.UpdateIcon?.Dispose();
|
this.UpdateIcon?.Dispose();
|
||||||
|
|
@ -126,7 +148,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
if (!this.downloadThread.Join(4000))
|
if (!this.downloadThread.Join(4000))
|
||||||
{
|
{
|
||||||
Log.Error("Plugin Image Download thread has not cancelled in time.");
|
Log.Error("Plugin Image Download thread has not cancelled in time");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.downloadToken?.Dispose();
|
this.downloadToken?.Dispose();
|
||||||
|
|
@ -326,11 +348,14 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
data.EnsureSuccessStatusCode();
|
data.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var bytes = await data.Content.ReadAsByteArrayAsync();
|
var bytes = await data.Content.ReadAsByteArrayAsync();
|
||||||
|
this.loadQueue.Add(() =>
|
||||||
|
{
|
||||||
if (!TryLoadIcon(bytes, url, manifest, interfaceManager, out var icon))
|
if (!TryLoadIcon(bytes, url, manifest, interfaceManager, out var icon))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.pluginIconMap[manifest.InternalName] = icon;
|
this.pluginIconMap[manifest.InternalName] = icon;
|
||||||
Log.Verbose($"Plugin icon for {manifest.InternalName} downloaded");
|
Log.Verbose($"Plugin icon for {manifest.InternalName} downloaded");
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -417,10 +442,13 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
var useTesting = pluginManager.UseTesting(manifest);
|
var useTesting = pluginManager.UseTesting(manifest);
|
||||||
var urls = this.GetPluginImageUrls(manifest, isThirdParty, useTesting);
|
var urls = this.GetPluginImageUrls(manifest, isThirdParty, useTesting);
|
||||||
|
|
||||||
if (urls != null)
|
if (urls != null)
|
||||||
{
|
{
|
||||||
|
var imageBytes = new byte[urls.Count][];
|
||||||
|
|
||||||
var didAny = false;
|
var didAny = false;
|
||||||
var pluginImages = new TextureWrap[urls.Count];
|
|
||||||
for (var i = 0; i < urls.Count; i++)
|
for (var i = 0; i < urls.Count; i++)
|
||||||
{
|
{
|
||||||
var url = urls[i];
|
var url = urls[i];
|
||||||
|
|
@ -452,25 +480,41 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
data.EnsureSuccessStatusCode();
|
data.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var bytes = await data.Content.ReadAsByteArrayAsync();
|
var bytes = await data.Content.ReadAsByteArrayAsync();
|
||||||
if (!TryLoadImage(i, bytes, url, manifest, interfaceManager, out var image))
|
imageBytes[i] = bytes;
|
||||||
continue;
|
|
||||||
|
|
||||||
|
|
||||||
Log.Verbose($"Plugin image{i + 1} for {manifest.InternalName} downloaded");
|
Log.Verbose($"Plugin image{i + 1} for {manifest.InternalName} downloaded");
|
||||||
pluginImages[i] = image;
|
|
||||||
|
|
||||||
didAny = true;
|
didAny = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didAny)
|
if (didAny)
|
||||||
{
|
{
|
||||||
|
this.loadQueue.Add(() =>
|
||||||
|
{
|
||||||
|
var pluginImages = new TextureWrap[urls.Count];
|
||||||
|
|
||||||
|
for (var i = 0; i < imageBytes.Length; i++)
|
||||||
|
{
|
||||||
|
var bytes = imageBytes[i];
|
||||||
|
if (bytes == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!TryLoadImage(i, bytes, "queue", manifest, interfaceManager, out var image))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pluginImages[i] = image;
|
||||||
|
}
|
||||||
|
|
||||||
Log.Verbose($"Plugin images for {manifest.InternalName} downloaded");
|
Log.Verbose($"Plugin images for {manifest.InternalName} downloaded");
|
||||||
|
|
||||||
if (pluginImages.Contains(null))
|
if (pluginImages.Contains(null))
|
||||||
pluginImages = pluginImages.Where(image => image != null).ToArray();
|
pluginImages = pluginImages.Where(image => image != null).ToArray();
|
||||||
|
|
||||||
this.pluginImagesMap[manifest.InternalName] = pluginImages;
|
this.pluginImagesMap[manifest.InternalName] = pluginImages;
|
||||||
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue