From 90253d5f62867f4f24fa20daa4451330b8e8176c Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 22 Feb 2009 16:01:29 +0000 Subject: [PATCH] Check that OpenGL resources have really been allocated, before deleting them in Unload(). --- Source/Examples/OpenGL/FrameBufferObject.cs | 11 +++++++---- Source/Examples/OpenGL/JuliaSetFractal.cs | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Examples/OpenGL/FrameBufferObject.cs b/Source/Examples/OpenGL/FrameBufferObject.cs index b2e1751d..30e9ec65 100644 --- a/Source/Examples/OpenGL/FrameBufferObject.cs +++ b/Source/Examples/OpenGL/FrameBufferObject.cs @@ -206,11 +206,14 @@ namespace Examples.Tutorial public override void OnUnload(EventArgs e) { // Clean up what we allocated before exiting - GL.DeleteTextures(1, ref ColorTexture); - GL.DeleteTextures(1, ref DepthTexture); - GL.Ext.DeleteFramebuffers(1, ref FBOHandle); + if (ColorTexture != 0) + GL.DeleteTextures(1, ref ColorTexture); - base.OnUnload(e); + if (DepthTexture != 0) + GL.DeleteTextures(1, ref DepthTexture); + + if (FBOHandle != 0) + GL.Ext.DeleteFramebuffers(1, ref FBOHandle); } protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) diff --git a/Source/Examples/OpenGL/JuliaSetFractal.cs b/Source/Examples/OpenGL/JuliaSetFractal.cs index 3eb04f1f..95c52138 100644 --- a/Source/Examples/OpenGL/JuliaSetFractal.cs +++ b/Source/Examples/OpenGL/JuliaSetFractal.cs @@ -191,12 +191,15 @@ namespace Examples.Tutorial #endregion - #region OnUnLoad + #region OnUnload public override void OnUnload(EventArgs e) { - GL.DeleteTextures(1, ref TextureObject); - GL.DeleteProgram(ProgramObject); // implies deleting the previously flagged ShaderObjects + if (TextureObject != 0) + GL.DeleteTextures(1, ref TextureObject); + + if (ProgramObject != 0) + GL.DeleteProgram(ProgramObject); // implies deleting the previously flagged ShaderObjects } #endregion