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; } } }