]> git.tdb.fi Git - libs/gl.git/commitdiff
Check glGetString result for being null
authorMikko Rasa <tdb@tdb.fi>
Sun, 23 Oct 2016 12:35:24 +0000 (15:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 23 Oct 2016 12:35:24 +0000 (15:35 +0300)
source/extension.cpp

index 8512046f28465092d02aa948ac0e153987ddedfc..e233ee0012eb60563366d7061acf682ae92f96b9 100644 (file)
@@ -81,18 +81,21 @@ bool is_supported(const string &ext)
                        extensions.insert(exts.begin(), exts.end());
                }
 
-               string renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
-               if(renderer.find("Radeon")!=string::npos || renderer.find("AMD")!=string::npos)
+               if(const char *renderer_ptr = reinterpret_cast<const char *>(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<const char *>(glGetString(GL_VERSION));
+       const char *gl_ver_ptr = reinterpret_cast<const char *>(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<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
+       const char *glsl_ver_ptr = reinterpret_cast<const char *>(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);