diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 1d099bb33d..d10bc1a138 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -73,7 +73,9 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ), cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ), mainBuffer( 0 ), overlayBuffer( 0 ) { -#if wxCHECK_VERSION( 3, 0, 3 ) +// IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4 +// starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER) +#if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 ) const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 }; if( !IsDisplaySupported( attr ) ) @@ -83,12 +85,19 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, if( glMainContext == NULL ) { glMainContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this ); + + if( !glMainContext ) + throw std::runtime_error( "Could not create the main OpenGL context" ); + glPrivContext = glMainContext; shader = new SHADER(); } else { glPrivContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this, glMainContext ); + + if( !glPrivContext ) + throw std::runtime_error( "Could not create a private OpenGL context" ); } ++instanceCounter; diff --git a/common/gl_context_mgr.cpp b/common/gl_context_mgr.cpp index 016ebde561..5b76b2d2db 100644 --- a/common/gl_context_mgr.cpp +++ b/common/gl_context_mgr.cpp @@ -24,6 +24,7 @@ */ #include +#include 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* 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 ) ); return context; @@ -53,13 +62,11 @@ void GL_CONTEXT_MANAGER::DestroyCtx( wxGLContext* aContext ) else { // Do not delete unknown GL contexts - assert( false ); + wxFAIL; } if( m_glCtx == aContext ) - { m_glCtx = NULL; - } } @@ -78,7 +85,7 @@ void GL_CONTEXT_MANAGER::DeleteAll() 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(); 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 ) { - assert( m_glContexts.count( aContext ) > 0 ); + wxCHECK( m_glContexts.count( aContext ) > 0, /* void */ ); if( m_glCtx == aContext ) { @@ -106,9 +113,8 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) } 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 ) ); } }