Corrected the last instance check in OPENGL_GAL.

This commit is contained in:
Maciej Suminski 2016-06-10 17:07:12 +02:00
parent 5850b1ced0
commit b7ec4ea160
2 changed files with 18 additions and 4 deletions

View File

@ -51,6 +51,7 @@ static void InitTesselatorCallbacks( GLUtesselator* aTesselator );
static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 };
wxGLContext* OPENGL_GAL::glMainContext = NULL;
int OPENGL_GAL::instanceCounter = 0;
GLuint OPENGL_GAL::fontTexture = 0;
bool OPENGL_GAL::isBitmapFontLoaded = false;
SHADER* OPENGL_GAL::shader = NULL;
@ -74,6 +75,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
glPrivContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this, glMainContext );
}
++instanceCounter;
// Check if OpenGL requirements are met
runTest();
@ -142,6 +145,7 @@ OPENGL_GAL::~OPENGL_GAL()
{
GL_CONTEXT_MANAGER::Get().LockCtx( glPrivContext );
--instanceCounter;
glFlush();
gluDeleteTess( tesselator );
ClearCache();
@ -151,9 +155,18 @@ OPENGL_GAL::~OPENGL_GAL()
delete nonCachedManager;
delete overlayManager;
GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext );
// If it was the main context, then it will be deleted
// when the last OpenGL GAL instance is destroyed (a few lines below)
if( glPrivContext != glMainContext )
GL_CONTEXT_MANAGER::Get().DestroyCtx( glPrivContext );
// Are destroying the last GAL instance?
if( glPrivContext == glMainContext )
if( instanceCounter == 0 )
{
GL_CONTEXT_MANAGER::Get().LockCtx( glMainContext );
if( isBitmapFontLoaded )
{
glDeleteTextures( 1, &fontTexture );
@ -161,11 +174,11 @@ OPENGL_GAL::~OPENGL_GAL()
}
delete shader;
glMainContext = NULL;
GL_CONTEXT_MANAGER::Get().UnlockCtx( glMainContext );
GL_CONTEXT_MANAGER::Get().DestroyCtx( glMainContext );
}
GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext );
GL_CONTEXT_MANAGER::Get().DestroyCtx( glPrivContext );
}

View File

@ -275,6 +275,7 @@ private:
static wxGLContext* glMainContext; ///< Parent OpenGL context
wxGLContext* glPrivContext; ///< Canvas-specific OpenGL context
static int instanceCounter; ///< GL GAL instance counter
wxEvtHandler* mouseListener;
wxEvtHandler* paintListener;