diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 4b6c22d086..1317e3a572 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -42,7 +42,9 @@ using namespace KIGFX; static void InitTesselatorCallbacks( GLUtesselator* aTesselator ); static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 }; + wxGLContext* OPENGL_GAL::glContext = NULL; +int OPENGL_GAL::instanceCounter = 0; OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener, const wxString& aName ) : @@ -59,6 +61,7 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, // Check if OpenGL requirements are met runTest(); + ++instanceCounter; // Make VBOs use shaders cachedManager.SetShader( shader ); @@ -119,6 +122,11 @@ OPENGL_GAL::~OPENGL_GAL() { glFlush(); + if( --instanceCounter == 0 ) + { + delete OPENGL_GAL::glContext; + } + gluDeleteTess( tesselator ); ClearCache(); } diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 83598baf68..93ca9d90df 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -261,6 +261,7 @@ private: static wxGLContext* glContext; ///< OpenGL context of wxWidgets wxEvtHandler* mouseListener; wxEvtHandler* paintListener; + static int instanceCounter; // Vertex buffer objects related fields typedef std::map< unsigned int, boost::shared_ptr > GROUPS_MAP;