Check GLEW functions exist before calling them

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6235
This commit is contained in:
Roberto Fernandez Bautista 2020-10-30 19:35:24 +00:00
parent 6c07ebe5f2
commit 3404f4e86b
5 changed files with 33 additions and 17 deletions

View File

@ -65,7 +65,8 @@ CACHED_CONTAINER_GPU::~CACHED_CONTAINER_GPU()
if( m_isMapped )
Unmap();
glDeleteBuffers( 1, &m_glBufferHandle );
if( glDeleteBuffers )
glDeleteBuffers( 1, &m_glBufferHandle );
}
@ -73,6 +74,10 @@ void CACHED_CONTAINER_GPU::Map()
{
wxCHECK( !IsMapped(), /*void*/ );
// OpenGL version might suddenly stop being available in Windows when an RDP session is started
if( !glBindBuffer )
throw std::runtime_error( "OpenGL no longer available!" );
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
m_vertices = static_cast<VERTEX*>( glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE ) );

View File

@ -51,7 +51,9 @@ CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) :
CACHED_CONTAINER_RAM::~CACHED_CONTAINER_RAM()
{
glDeleteBuffers( 1, &m_verticesBuffer );
if( glDeleteBuffers )
glDeleteBuffers( 1, &m_verticesBuffer );
free( m_vertices );
}

View File

@ -85,8 +85,11 @@ GPU_CACHED_MANAGER::~GPU_CACHED_MANAGER()
{
if( m_buffersInitialized )
{
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glDeleteBuffers( 1, &m_indicesBuffer );
if( glBindBuffer )
glBindBuffer( GL_ARRAY_BUFFER, 0 );
if( glDeleteBuffers )
glDeleteBuffers( 1, &m_indicesBuffer );
}
}

View File

@ -399,8 +399,11 @@ void OPENGL_COMPOSITOR::clean()
m_buffers.clear();
glDeleteFramebuffersEXT( 1, &m_mainFbo );
glDeleteRenderbuffersEXT( 1, &m_depthBuffer );
if( glDeleteFramebuffersEXT )
glDeleteFramebuffersEXT( 1, &m_mainFbo );
if( glDeleteRenderbuffersEXT )
glDeleteRenderbuffersEXT( 1, &m_depthBuffer );
m_initialized = false;
}

View File

@ -59,20 +59,23 @@ SHADER::~SHADER()
if( isProgramCreated )
{
// Delete the shaders and the program
for( std::deque<GLuint>::iterator it = shaderNumbers.begin();
it != shaderNumbers.end(); ++it )
if( glIsShader )
{
GLuint shader = *it;
if( glIsShader( shader ) )
// Delete the shaders and the program
for( std::deque<GLuint>::iterator it = shaderNumbers.begin(); it != shaderNumbers.end();
++it )
{
glDetachShader( programNumber, shader );
glDeleteShader( shader );
}
}
GLuint shader = *it;
glDeleteProgram( programNumber );
if( glIsShader( shader ) )
{
glDetachShader( programNumber, shader );
glDeleteShader( shader );
}
}
glDeleteProgram( programNumber );
}
}
}