From 99ee3c9fd70aed6aabf8ce0edb000d4d7b26ab57 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Thu, 27 Dec 2007 14:57:15 +0000 Subject: [PATCH] FIXED: Shader-related crashes when uninitializing OpenGL renderer --- trunk/src/win32/OpenGL.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/trunk/src/win32/OpenGL.cpp b/trunk/src/win32/OpenGL.cpp index 170d1eed..23bdf7d9 100644 --- a/trunk/src/win32/OpenGL.cpp +++ b/trunk/src/win32/OpenGL.cpp @@ -89,6 +89,7 @@ private: GLFONT font; int VertexShader,FragmentShader,textureLocation,ShaderProgram,g_location_grayScaleWeights; char *VertexShaderSource,*FragmentShaderSource; + bool shaderFuncInited; void initializeMatrices( int w, int h ); bool initializeTexture( int w, int h ); @@ -210,6 +211,8 @@ void OpenGLDisplay::SetGLSLShaderConstants() } void OpenGLDisplay::DeInitGLSLShader (void) { + if( !shaderFuncInited ) return; + if (VertexShader != 0){ glDeleteObjectARB(VertexShader); } @@ -219,7 +222,7 @@ void OpenGLDisplay::DeInitGLSLShader (void) { if (FragmentShader != 0){ glDeleteObjectARB(ShaderProgram); } - + shaderFuncInited = false; } OpenGLDisplay::OpenGLDisplay() @@ -232,6 +235,7 @@ OpenGLDisplay::OpenGLDisplay() size = 0.0f; failed = false; filterData = NULL; + shaderFuncInited = false; } @@ -268,8 +272,7 @@ void OpenGLDisplay::DisableOpenGL() void OpenGLDisplay::cleanup() { - - DeInitGLSLShader(); + DeInitGLSLShader(); if(texture != 0) { glDeleteTextures(1, &texture); @@ -318,6 +321,7 @@ bool OpenGLDisplay::initialize() glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)wglGetProcAddress("glGetUniformLocationARB"); glUniform4fARB = (PFNGLUNIFORM4FARBPROC)wglGetProcAddress("glUniform4fARB"); glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB"); + shaderFuncInited = true; } initializeMatrices( theApp.surfaceSizeX, theApp.surfaceSizeY ); @@ -359,15 +363,11 @@ void OpenGLDisplay::clear() void OpenGLDisplay::render() { clear(); - if (theApp.GLSLShaders){ + if (theApp.GLSLShaders && shaderFuncInited){ InitGLSLShader(); glUseProgramObjectARB( ShaderProgram ); SetGLSLShaderConstants(); } - else - { - DeInitGLSLShader(); - } int pitch = theApp.filterWidth * (systemColorDepth>>3) + 4;