From 5679dba97877002e6f7677fa0bf825f5cf365f49 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 22 Feb 2022 14:29:50 -0800 Subject: [PATCH] Actually dispose graphics resources --- src/Game.cs | 5 ++++- src/Graphics/GraphicsDevice.cs | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Game.cs b/src/Game.cs index 5dab4d7..9ade955 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -134,9 +134,12 @@ namespace MoonWorks Draw(timestep, alpha); - GraphicsDevice.SubmitDestroyCommandBuffer(); } + + GraphicsDevice.SubmitDestroyCommandBuffer(); } + + GraphicsDevice.Dispose(); } private void HandleSDLEvents() diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index ee2566f..c1c0e0f 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -101,16 +101,18 @@ namespace MoonWorks.Graphics { lock (resources) { - foreach (var resource in resources) - { - if (resource.TryGetTarget(out var target)) + for (var i = resources.Count - 1; i >= 0; i--) + { + var resource = resources[i]; + if (resource.TryGetTarget(out var target)) { target.Dispose(); } - } + } resources.Clear(); } + SubmitDestroyCommandBuffer(); Refresh.Refresh_DestroyDevice(Handle); } @@ -118,7 +120,6 @@ namespace MoonWorks.Graphics } } - // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources ~GraphicsDevice() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method