@ -24,6 +24,7 @@
*/
*/
# include <gl_context_mgr.h>
# include <gl_context_mgr.h>
# include <wx/debug.h>
GL_CONTEXT_MANAGER & GL_CONTEXT_MANAGER : : Get ( )
GL_CONTEXT_MANAGER & GL_CONTEXT_MANAGER : : Get ( )
{
{
@ -35,8 +36,16 @@ GL_CONTEXT_MANAGER& GL_CONTEXT_MANAGER::Get()
wxGLContext * GL_CONTEXT_MANAGER : : CreateCtx ( wxGLCanvas * aCanvas , const wxGLContext * aOther )
wxGLContext * GL_CONTEXT_MANAGER : : CreateCtx ( wxGLCanvas * aCanvas , const wxGLContext * aOther )
{
{
wxGLContext * context = new wxGLContext ( aCanvas , aOther ) ;
wxGLContext * context = new wxGLContext ( aCanvas , aOther ) ;
assert ( context /* && context->IsOK() */ ) ; // IsOK() is available in wx3.1+
assert ( m_glContexts . count ( context ) = = 0 ) ;
wxCHECK ( context , nullptr ) ;
# if wxCHECK_VERSION( 3, 1, 0 )
if ( ! context - > IsOK ( ) )
{
delete context ;
return nullptr ;
}
# endif /* wxCHECK_VERSION( 3, 1, 0 ) */
m_glContexts . insert ( std : : make_pair ( context , aCanvas ) ) ;
m_glContexts . insert ( std : : make_pair ( context , aCanvas ) ) ;
return context ;
return context ;
@ -53,13 +62,11 @@ void GL_CONTEXT_MANAGER::DestroyCtx( wxGLContext* aContext )
else
else
{
{
// Do not delete unknown GL contexts
// Do not delete unknown GL contexts
assert ( false ) ;
wxFAIL ;
}
}
if ( m_glCtx = = aContext )
if ( m_glCtx = = aContext )
{
m_glCtx = NULL ;
m_glCtx = NULL ;
}
}
}
@ -78,7 +85,7 @@ void GL_CONTEXT_MANAGER::DeleteAll()
void GL_CONTEXT_MANAGER : : LockCtx ( wxGLContext * aContext , wxGLCanvas * aCanvas )
void GL_CONTEXT_MANAGER : : LockCtx ( wxGLContext * aContext , wxGLCanvas * aCanvas )
{
{
assert ( aCanvas | | m_glContexts . count ( aContext ) > 0 ) ;
wxCHECK ( aCanvas | | m_glContexts . count ( aContext ) > 0 , /* void */ ) ;
m_glCtxMutex . lock ( ) ;
m_glCtxMutex . lock ( ) ;
wxGLCanvas * canvas = aCanvas ? aCanvas : m_glContexts . at ( aContext ) ;
wxGLCanvas * canvas = aCanvas ? aCanvas : m_glContexts . at ( aContext ) ;
@ -97,7 +104,7 @@ void GL_CONTEXT_MANAGER::LockCtx( wxGLContext* aContext, wxGLCanvas* aCanvas )
void GL_CONTEXT_MANAGER : : UnlockCtx ( wxGLContext * aContext )
void GL_CONTEXT_MANAGER : : UnlockCtx ( wxGLContext * aContext )
{
{
assert ( m_glContexts . count ( aContext ) > 0 ) ;
wxCHECK ( m_glContexts . count ( aContext ) > 0 , /* void */ ) ;
if ( m_glCtx = = aContext )
if ( m_glCtx = = aContext )
{
{
@ -106,9 +113,8 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext )
}
}
else
else
{
{
wxLogDebug (
" Trying to unlock GL context mutex from a wrong context: aContext %p m_glCtx %p " ,
aContext , m_glCtx ) ;
wxFAIL_MSG ( wxString : : Format ( " Trying to unlock GL context mutex from "
" a wrong context: aContext %p m_glCtx %p " , aContext , m_glCtx ) ) ;
}
}
}
}