diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index c44ded3..8255203 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -380,8 +380,7 @@ namespace MoonWorks.Graphics { foreach (var resource in resources) { - var target = resource.Target; - if (target is IDisposable disposable) + if (resource.Target is IDisposable disposable) { disposable.Dispose(); } diff --git a/src/Graphics/GraphicsResource.cs b/src/Graphics/GraphicsResource.cs index dc4a451..e124e4b 100644 --- a/src/Graphics/GraphicsResource.cs +++ b/src/Graphics/GraphicsResource.cs @@ -11,18 +11,18 @@ namespace MoonWorks.Graphics public bool IsDisposed { get; private set; } protected abstract Action QueueDestroyFunction { get; } - internal GCHandle selfReference; + private GCHandle SelfReference; - public GraphicsResource(GraphicsDevice device, bool trackResource = true) + protected GraphicsResource(GraphicsDevice device) { Device = device; - selfReference = GCHandle.Alloc(this, GCHandleType.Weak); - Device.AddResourceReference(selfReference); + SelfReference = GCHandle.Alloc(this, GCHandleType.Weak); + Device.AddResourceReference(SelfReference); } - internal GraphicsResourceDisposalHandle CreateDisposalHandle() - { + private GraphicsResourceDisposalHandle CreateDisposalHandle() + { return new GraphicsResourceDisposalHandle { QueueDestroyAction = QueueDestroyFunction, @@ -30,15 +30,15 @@ namespace MoonWorks.Graphics }; } - protected virtual void Dispose(bool disposing) + protected void Dispose(bool disposing) { if (!IsDisposed) { if (Handle != IntPtr.Zero) { QueueDestroyFunction(Device.Handle, Handle); - Device.RemoveResourceReference(selfReference); - selfReference.Free(); + Device.RemoveResourceReference(SelfReference); + SelfReference.Free(); Handle = IntPtr.Zero; } @@ -50,6 +50,8 @@ namespace MoonWorks.Graphics ~GraphicsResource() { #if DEBUG + // If the graphics device associated with this resource was already disposed, we assume + // that your game is in the middle of shutting down. if (!IsDisposed && Device != null && !Device.IsDisposed) { // If you see this log message, you leaked a graphics resource without disposing it!