Instance counter for OPENGL_GAL to avoid double freeing.

This commit is contained in:
Maciej Suminski 2016-05-02 15:56:16 +02:00
parent dbff9ad786
commit c0465e5519
2 changed files with 9 additions and 0 deletions

View File

@ -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();
}

View File

@ -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<VERTEX_ITEM> > GROUPS_MAP;