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