From cf89f0205dfad2c8df47217e34302da71bbeda01 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 23 Oct 2016 15:35:24 +0300 Subject: [PATCH] Check glGetString result for being null --- source/extension.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/source/extension.cpp b/source/extension.cpp index 8512046f..e233ee00 100644 --- a/source/extension.cpp +++ b/source/extension.cpp @@ -81,18 +81,21 @@ bool is_supported(const string &ext) extensions.insert(exts.begin(), exts.end()); } - string renderer = reinterpret_cast(glGetString(GL_RENDERER)); - if(renderer.find("Radeon")!=string::npos || renderer.find("AMD")!=string::npos) + if(const char *renderer_ptr = reinterpret_cast(glGetString(GL_RENDERER))) { - /* Radeon doesn't process NV_primitive_restart correctly and treats - the restart index as a normal element if the indices are stored in a - buffer. */ - extensions.erase("GL_NV_primitive_restart"); - - /* AMD's uniform buffer objects only work with the core version of - shaders. */ - if(!(get_gl_version()>=Version(2, 0))) - extensions.erase("GL_ARB_uniform_buffer_object"); + string renderer = renderer_ptr; + if(renderer.find("Radeon")!=string::npos || renderer.find("AMD")!=string::npos) + { + /* Radeon doesn't process NV_primitive_restart correctly and treats + the restart index as a normal element if the indices are stored in a + buffer. */ + extensions.erase("GL_NV_primitive_restart"); + + /* AMD's uniform buffer objects only work with the core version of + shaders. */ + if(!(get_gl_version()>=Version(2, 0))) + extensions.erase("GL_ARB_uniform_buffer_object"); + } } if(const char *disable_ptr = getenv("MSPGL_DISABLE_EXTENSIONS")) @@ -119,7 +122,11 @@ GLApi get_gl_api() inline Version _get_gl_version() { - string gl_ver = reinterpret_cast(glGetString(GL_VERSION)); + const char *gl_ver_ptr = reinterpret_cast(glGetString(GL_VERSION)); + if(!gl_ver_ptr) + throw runtime_error("OpenGL version not available"); + + string gl_ver = gl_ver_ptr; if(!gl_ver.compare(0, 10, "OpenGL ES ")) gl_ver.erase(0, 10); @@ -143,7 +150,11 @@ const Version &get_gl_version() inline Version _get_glsl_version() { - string glsl_ver = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + const char *glsl_ver_ptr = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + if(!glsl_ver_ptr) + throw runtime_error("GLSL version not available"); + + string glsl_ver = glsl_ver_ptr; if(!glsl_ver.compare(0, 18, "OpenGL ES GLSL ES ")) glsl_ver.erase(0, 18); -- 2.45.2