From 5c8a5307d623af2d37821562e68e828f657dfc3b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 12 Mar 2018 15:55:35 +0000 Subject: [PATCH] From Colin McDonald, "If the glCreateProgram in osg::Program fails for any reason, then subsequently Program::PerContextProgram::linkProgram would crash. I've put in some checks to prevent that." --- src/osg/Program.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index b41d27b81..d54fb372f 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -656,7 +656,15 @@ Program::PerContextProgram::PerContextProgram(const Program* program, unsigned i { _extensions = GLExtensions::Get( _contextID, true ); _glProgramHandle = _extensions->glCreateProgram(); - _ownsProgramHandle = true; + + if (_glProgramHandle) + { + _ownsProgramHandle = true; + } + else + { + OSG_WARN << "Unable to create osg::Program \"" << _program->getName() << "\"" << " contextID=" << _contextID << std::endl; + } } requestLink(); } @@ -682,6 +690,8 @@ void Program::PerContextProgram::linkProgram(osg::State& state) if( ! _needsLink ) return; _needsLink = false; + if (!_glProgramHandle) return; + OSG_INFO << "Linking osg::Program \"" << _program->getName() << "\"" << " id=" << _glProgramHandle << " contextID=" << _contextID @@ -709,7 +719,7 @@ void Program::PerContextProgram::linkProgram(osg::State& state) if (!_loadedBinary) { const GLsizei shaderMaxCount = 20; - GLsizei shadersCount; + GLsizei shadersCount = 0; GLuint shaderObjectHandle[shaderMaxCount]; _extensions->glGetAttachedShaders(_glProgramHandle, shaderMaxCount, &shadersCount, shaderObjectHandle); @@ -1035,6 +1045,8 @@ void Program::PerContextProgram::linkProgram(osg::State& state) bool Program::PerContextProgram::validateProgram() { + if (!_glProgramHandle) return false; + GLint validated = GL_FALSE; _extensions->glValidateProgram( _glProgramHandle ); _extensions->glGetProgramiv( _glProgramHandle, GL_VALIDATE_STATUS, &validated ); @@ -1057,11 +1069,15 @@ bool Program::PerContextProgram::validateProgram() bool Program::PerContextProgram::getInfoLog( std::string& infoLog ) const { + if (!_glProgramHandle) return false; + return _extensions->getProgramInfoLog( _glProgramHandle, infoLog ); } Program::ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::State& state) { + if (!_glProgramHandle) return 0; + linkProgram(state); GLint binaryLength = 0; _extensions->glGetProgramiv( _glProgramHandle, GL_PROGRAM_BINARY_LENGTH, &binaryLength ); @@ -1079,5 +1095,7 @@ Program::ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::St void Program::PerContextProgram::useProgram() const { + if (!_glProgramHandle) return; + _extensions->glUseProgram( _glProgramHandle ); }