From b83c148e108faea686124df1bd7953211759736b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 3 Jun 2016 15:46:13 +0200 Subject: [PATCH] Delete OpenGL context on GLCanvas subclasses destruction. --- 3d-viewer/3d_canvas.cpp | 1 + 3d-viewer/3d_model_viewer/c3d_model_viewer.cpp | 1 + common/gal/opengl/opengl_gal.cpp | 1 + common/gl_context_mgr.cpp | 17 +++++++++++++++++ include/gl_context_mgr.h | 8 ++++++++ 5 files changed, 28 insertions(+) diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index 54d647606d..b2b1d95dfe 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -127,6 +127,7 @@ EDA_3D_CANVAS::~EDA_3D_CANVAS() delete m_model_parsers_list[i]; GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC ); } diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index 64aef1c33b..105fc749ff 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -109,6 +109,7 @@ C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER() m_ogl_3dmodel = NULL; GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); + GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC ); } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 0a7f5c2019..fcd73670b0 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -155,6 +155,7 @@ OPENGL_GAL::~OPENGL_GAL() } GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext ); + GL_CONTEXT_MANAGER::Get().DestroyCtx( glPrivContext ); } diff --git a/common/gl_context_mgr.cpp b/common/gl_context_mgr.cpp index 5a82722e6f..fce9c4450d 100644 --- a/common/gl_context_mgr.cpp +++ b/common/gl_context_mgr.cpp @@ -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() { for( auto& ctx : m_glContexts ) diff --git a/include/gl_context_mgr.h b/include/gl_context_mgr.h index 4bed13babd..de5f7d0bb4 100644 --- a/include/gl_context_mgr.h +++ b/include/gl_context_mgr.h @@ -47,6 +47,14 @@ public: */ 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 * destroys all managed OpenGL contexts. This method should be called in the