From 28de6ede4521188e424ea5aad6c042421b1cbc09 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 21 Mar 2023 16:55:24 +0900 Subject: [PATCH] Add a finaliser to Veldrid UBO disposal --- .../Graphics/OpenGL/Buffers/GLUniformBuffer.cs | 2 +- .../Veldrid/Buffers/VeldridUniformBuffer.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/OpenGL/Buffers/GLUniformBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/GLUniformBuffer.cs index a539086778..45f208e0eb 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/GLUniformBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/GLUniformBuffer.cs @@ -64,7 +64,7 @@ private void setData(ref TData data) public void Dispose() { - Dispose(true); + renderer.ScheduleDisposal(v => v.Dispose(true), this); GC.SuppressFinalize(this); } diff --git a/osu.Framework/Graphics/Veldrid/Buffers/VeldridUniformBuffer.cs b/osu.Framework/Graphics/Veldrid/Buffers/VeldridUniformBuffer.cs index ccf9eadd3d..233d6fd459 100644 --- a/osu.Framework/Graphics/Veldrid/Buffers/VeldridUniformBuffer.cs +++ b/osu.Framework/Graphics/Veldrid/Buffers/VeldridUniformBuffer.cs @@ -44,10 +44,28 @@ public TData Data public ResourceSet GetResourceSet(ResourceLayout layout) => set ??= renderer.Factory.CreateResourceSet(new ResourceSetDescription(layout, buffer)); + ~VeldridUniformBuffer() + { + renderer.ScheduleDisposal(v => v.Dispose(false), this); + } + public void Dispose() { + renderer.ScheduleDisposal(v => v.Dispose(true), this); + GC.SuppressFinalize(this); + } + + protected bool IsDisposed { get; private set; } + + protected virtual void Dispose(bool disposing) + { + if (IsDisposed) + return; + buffer.Dispose(); set?.Dispose(); + + IsDisposed = true; } } }