fix: correctly enqueue textures for destroy if they're GC'd

This commit is contained in:
goat 2023-03-26 00:22:09 +01:00
parent 70d5cb5856
commit 14ce85627d
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 26 additions and 5 deletions

View file

@ -21,6 +21,14 @@ public class DalamudTextureWrap : TextureWrap
this.wrappedWrap = wrappingWrap;
}
/// <summary>
/// Finalizes an instance of the <see cref="DalamudTextureWrap"/> class.
/// </summary>
~DalamudTextureWrap()
{
this.Dispose(false);
}
/// <summary>
/// Gets the ImGui handle of the texture.
/// </summary>
@ -41,7 +49,8 @@ public class DalamudTextureWrap : TextureWrap
/// </summary>
public void Dispose()
{
Service<InterfaceManager>.Get().EnqueueDeferredDispose(this);
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
@ -51,4 +60,12 @@ public class DalamudTextureWrap : TextureWrap
{
this.wrappedWrap.Dispose();
}
private void Dispose(bool disposing)
{
if (disposing)
{
Service<InterfaceManager>.GetNullable()?.EnqueueDeferredDispose(this);
}
}
}

View file

@ -606,12 +606,16 @@ internal class InterfaceManager : IDisposable, IServiceType
this.RenderImGui();
foreach (var texture in this.deferredDisposeTextures)
if (this.deferredDisposeTextures.Count > 0)
{
texture.RealDispose();
}
Log.Verbose("[IM] Disposing {Count} textures", this.deferredDisposeTextures.Count);
foreach (var texture in this.deferredDisposeTextures)
{
texture.RealDispose();
}
this.deferredDisposeTextures.Clear();
this.deferredDisposeTextures.Clear();
}
return this.presentHook.Original(swapChain, syncInterval, presentFlags);
}