glGetString doesn't check for NULL context for GL_VERSION or GL_SHADING_LANGUAGE_VERSION

531 views
Skip to first unread message

Greg Marr

unread,
Jul 22, 2015, 2:29:47 PM7/22/15
to angleproject
In the version of Angle included in Qt 5.3.2 and earlier, calling
glGetString(GL_VERSION) was safe even if no context had
been created yet.  The function explicitly checked for the global
context being NULL in the cases where it needed to use it, and
for GL_VERSION, it didn't even need to use it.

That has changed in the version of Angle used in Qt 5.5.0.
glGetString for GL_VERSION and GL_SHADING_LANGUAGE_VERSION
now use the global context pointer without checking it for NULL,
resulting in an access violation.

That changed here:

Thu May 30 00:06:01 2013
Return correct GL version and GLSL ES version strings when we are running in an ES3 context.

TRAC #22865

Is it legal to call glGetString(GL_VERSION) without a context?

Shannon Woods

unread,
Jul 22, 2015, 4:40:25 PM7/22/15
to angleproject, gr...@alum.wpi.edu
Issuing *any* GL command without a context results in undefined behavior:

"Issuing GL commands when the program is not connected to a context results in undefined behavior." (ES 3.0.4 specification, p5, sec 2.1)

Some ES implementations may execute commands without a context, but others may not, or may crash, or may return junk data. 

The ES version is specific to a context-- an implementation may be capable of generating both ES2 and ES3.0 contexts, for example, so querying the version needs to be done from an already-created context. If what you're trying to find out is what versions of ES a given implementation is able to support, you'll want to check the attributes of the OpenGL ES config you'll use to create the context for EGL_OPENGL_ES2_BIT or EGL_OPENGL_ES3_BIT. (Or EGL_OPENGL_ES_BIT, if you're looking for ES 1.x, but ANGLE in particular does not currently support ES 1.x.) 

Shannon Woods

unread,
Jul 22, 2015, 4:45:46 PM7/22/15
to angleproject, shanno...@chromium.org, gr...@alum.wpi.edu
(That said, ANGLE should check the pointer before dereferencing it. I'll file a bug.)

Greg Marr

unread,
Jul 22, 2015, 9:47:10 PM7/22/15
to angleproject, shanno...@chromium.org
On Wednesday, July 22, 2015 at 4:40:25 PM UTC-4, Shannon Woods wrote:
Issuing *any* GL command without a context results in undefined behavior:

"Issuing GL commands when the program is not connected to a context results in undefined behavior." (ES 3.0.4 specification, p5, sec 2.1)

Excellent, thanks for that reference.  I was looking around for any information about whether the code I was looking at was valid or not.

Reply all
Reply to author
Forward
0 new messages