From 3bbbd672beea38b2c73f7caf01c1887974c5ecae Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Sat, 29 Dec 2018 00:23:29 -0600 Subject: [PATCH] Changed implementation of IDisposable to proper way. --- .../ScreenSystem/ScreenManager.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs index 6275d52..d3832e5 100644 --- a/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs +++ b/RecrownedAthenaeum/ScreenSystem/ScreenManager.cs @@ -1,10 +1,12 @@ -using Microsoft.Xna.Framework; +using Microsoft.Win32.SafeHandles; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using RecrownedAthenaeum.Camera; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -14,6 +16,8 @@ namespace RecrownedAthenaeum.ScreenSystem public class ScreenManager : IDisposable { + bool disposed = false; + public event FirstScreenChange RequireNextScreenEvent; private GraphicsDeviceManager graphics; private Screen previousScreen; @@ -131,7 +135,18 @@ namespace RecrownedAthenaeum.ScreenSystem public void Dispose() { - previousScreenRenderTarget?.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + public virtual void Dispose(bool disposing) + { + if (disposed) return; + if (disposing) + { + previousScreenRenderTarget?.Dispose(); + } + disposing = true; } } }