Delete OpenGL context on GLCanvas subclasses destruction.

This commit is contained in:
Maciej Suminski 2016-06-03 15:46:13 +02:00
parent 68b6da57c0
commit b83c148e10
5 changed files with 28 additions and 0 deletions

View File

@ -127,6 +127,7 @@ EDA_3D_CANVAS::~EDA_3D_CANVAS()
delete m_model_parsers_list[i]; delete m_model_parsers_list[i];
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
} }

View File

@ -109,6 +109,7 @@ C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER()
m_ogl_3dmodel = NULL; m_ogl_3dmodel = NULL;
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
} }

View File

@ -155,6 +155,7 @@ OPENGL_GAL::~OPENGL_GAL()
} }
GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext ); GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext );
GL_CONTEXT_MANAGER::Get().DestroyCtx( glPrivContext );
} }

View File

@ -42,6 +42,23 @@ wxGLContext* GL_CONTEXT_MANAGER::CreateCtx( wxGLCanvas* aCanvas, const wxGLConte
} }
void GL_CONTEXT_MANAGER::DestroyCtx( wxGLContext* aContext )
{
assert( m_glCtx != aContext );
if( m_glContexts.count( aContext ) && m_glCtx != aContext )
{
m_glContexts.erase( aContext );
delete aContext;
}
else
{
// Do not delete currently used or unknown GL contexts
assert( false );
}
}
void GL_CONTEXT_MANAGER::DeleteAll() void GL_CONTEXT_MANAGER::DeleteAll()
{ {
for( auto& ctx : m_glContexts ) for( auto& ctx : m_glContexts )

View File

@ -47,6 +47,14 @@ public:
*/ */
wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = NULL ); wxGLContext* CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther = NULL );
/**
* Function DestroyCtx
* destroys a managed OpenGL context. The context to be removed has to be created using
* GL_CONTEXT_MANAGER::CreateCtx() first.
* @param aContext is the OpenGL context to be destroyed. It will not be managed anymore.
*/
void DestroyCtx( wxGLContext* aContext );
/** /**
* Function DeleteAll * Function DeleteAll
* destroys all managed OpenGL contexts. This method should be called in the * destroys all managed OpenGL contexts. This method should be called in the