Dealing with inconsistent wxGLCanvas::IsDisplaySupported()

wxGLCanvas::IsDisplaySupported() handles wxGL_{MINOR,MAJOR}_VERSION
attributes only in 3.0.4. Since 3.1.0 the attributes are apparently not
supported, so instead wxGLContext::IsOK() is used (introduced in 3.1.0).

Fixes: lp:1775995
* https://bugs.launchpad.net/kicad/+bug/1775995
This commit is contained in:
Maciej Suminski 2018-06-11 12:25:20 +02:00
parent 3f783d2318
commit 813c1a2ba2
2 changed files with 26 additions and 11 deletions

View File

@ -73,7 +73,9 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ), mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ),
cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ), mainBuffer( 0 ), overlayBuffer( 0 ) 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 }; const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
if( !IsDisplaySupported( attr ) ) if( !IsDisplaySupported( attr ) )
@ -83,12 +85,19 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
if( glMainContext == NULL ) if( glMainContext == NULL )
{ {
glMainContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this ); glMainContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
if( !glMainContext )
throw std::runtime_error( "Could not create the main OpenGL context" );
glPrivContext = glMainContext; glPrivContext = glMainContext;
shader = new SHADER(); shader = new SHADER();
} }
else else
{ {
glPrivContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this, glMainContext ); glPrivContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this, glMainContext );
if( !glPrivContext )
throw std::runtime_error( "Could not create a private OpenGL context" );
} }
++instanceCounter; ++instanceCounter;

View File

@ -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+ wxCHECK( context, nullptr );
assert( m_glContexts.count( context ) == 0 );
#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( wxFAIL_MSG( wxString::Format( "Trying to unlock GL context mutex from "
"Trying to unlock GL context mutex from a wrong context: aContext %p m_glCtx %p", "a wrong context: aContext %p m_glCtx %p", aContext, m_glCtx ) );
aContext, m_glCtx );
} }
} }