From e7fd9eb296b7bf83c1e1ecd7e2a2e1b7a4e61725 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 24 Jul 2009 21:19:42 +0000 Subject: [PATCH] Implemented IDisposable pattern. --- Source/OpenTK/Platform/Egl/EglWindowInfo.cs | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/Egl/EglWindowInfo.cs b/Source/OpenTK/Platform/Egl/EglWindowInfo.cs index 25bf3103..706cc71e 100644 --- a/Source/OpenTK/Platform/Egl/EglWindowInfo.cs +++ b/Source/OpenTK/Platform/Egl/EglWindowInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Diagnostics; namespace OpenTK.Platform.Egl { @@ -12,6 +13,7 @@ namespace OpenTK.Platform.Egl IntPtr handle; EGLDisplay display; EGLSurface surface; + bool disposed; #endregion @@ -49,13 +51,41 @@ namespace OpenTK.Platform.Egl // Surface = Egl.CreatePbufferSurface(Display, config, null); //} + public void DestroySurface() + { + if (Surface.Handle != EGLSurface.None.Handle) + if (!Egl.DestroySurface(Display, Surface)) + Debug.Print("[Warning] Failed to destroy {0}:{1}.", Surface.GetType().Name, Surface); + } + #endregion #region IDisposable Members public void Dispose() { - throw new NotImplementedException(); + Dispose(true); + GC.SuppressFinalize(this); + } + + void Dispose(bool manual) + { + if (!disposed) + { + if (manual) + { + DestroySurface(); + } + else + { + Debug.Print("[Warning] Failed to destroy {0}:{1}.", this.GetType().Name, Handle); + } + } + } + + ~EglWindowInfo() + { + Dispose(false); } #endregion