aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-13 20:15:06 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-12-13 20:15:06 -0800
commit60a343b491c05218bced3a22d5ce7c24600e0203 (patch)
tree890c4aa0a4895ce2541caa483487d16ed38cf7d9
parent79191815d0721fc1d04770a9335919fe56c67d30 (diff)
parentb7036a68275a6ee2d18859d3a4fccee5f2900a7b (diff)
Merge pull request #1835 from juj/gl_get_null
glGetXXX fixes.
-rw-r--r--src/library_gl.js17
-rw-r--r--tests/gles2_conformance.cpp24
2 files changed, 28 insertions, 13 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index cc39b048..29f78c8a 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -210,21 +210,30 @@ var LibraryGL = {
},
get: function(name_, p, type) {
+ // Guard against user passing a null pointer.
+ // Note that GLES2 spec does not say anything about how passing a null pointer should be treated.
+ // Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but
+ // better to report an error instead of doing anything random.
+ if (!p) {
+#if GL_ASSERTIONS
+ Module.printErr('GL_INVALID_VALUE in glGet' + type + 'v(name=' + name_ + ': Function called with null out pointer!');
+#endif
+ GL.recordError(0x0501 /* GL_INVALID_VALUE */);
+ return;
+ }
var ret = undefined;
switch(name_) { // Handle a few trivial GLES values
case 0x8DFA: // GL_SHADER_COMPILER
ret = 1;
break;
case 0x8DF8: // GL_SHADER_BINARY_FORMATS
- if (type === 'Integer') {
- // fall through, see gles2_conformance.cpp
- } else {
+ if (type !== 'Integer') {
GL.recordError(0x0500); // GL_INVALID_ENUM
#if GL_ASSERTIONS
Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(GL_SHADER_BINARY_FORMATS): Invalid parameter type!');
#endif
- return;
}
+ return; // Do not write anything to the out pointer, since no binary formats are supported.
case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS
ret = 0;
break;
diff --git a/tests/gles2_conformance.cpp b/tests/gles2_conformance.cpp
index 80539f7f..77681bf4 100644
--- a/tests/gles2_conformance.cpp
+++ b/tests/gles2_conformance.cpp
@@ -30,6 +30,16 @@ int main(int argc, char *argv[])
glShaderBinary(1, &vs, 0, 0, 0);
assert(glGetError() != GL_NO_ERROR);
+ // Calling any of glGet() with null pointer should be detected and not crash.
+ // Note that native code can crash when passed a null pointer, and the GL spec does not say anything
+ // about this, so we spec that Emscripten GLES2 code should generate GL_INVALID_VALUE.
+ glGetBooleanv(GL_ACTIVE_TEXTURE, 0);
+ assert(glGetError() == GL_INVALID_VALUE);
+ glGetIntegerv(GL_ACTIVE_TEXTURE, 0);
+ assert(glGetError() == GL_INVALID_VALUE);
+ glGetFloatv(GL_ACTIVE_TEXTURE, 0);
+ assert(glGetError() == GL_INVALID_VALUE);
+
GLboolean b = GL_TRUE;
GLint i = -1;
GLfloat f = -1.f;
@@ -44,18 +54,14 @@ int main(int argc, char *argv[])
assert(f == 0.f);
// Currently testing that glGetIntegerv(GL_SHADER_BINARY_FORMATS) should be a no-op.
- // The spec is somewhat vague here, equally as good could be to return GL_INVALID_ENUM here.
- i = 123;
- glGetIntegerv(GL_SHADER_BINARY_FORMATS, &i);
+ int formats[10] = { 123 };
+ glGetIntegerv(GL_SHADER_BINARY_FORMATS, formats);
assert(glGetError() == GL_NO_ERROR);
- assert(i == 0);
+ assert(formats[0] == 123);
- // Spec does not say what to report on the following, but since GL_SHADER_BINARY_FORMATS is supposed
- // to return a a pointer to an array representing a list, the pointer can't be converted to bool or float,
- // so report a GL_INVALID_ENUM.
+ // Converting enums to booleans or floats would be odd, so test that the following report a GL_INVALID_ENUM.
glGetBooleanv(GL_SHADER_BINARY_FORMATS, &b);
- assert(glGetError() == GL_INVALID_ENUM);
-
+ assert(glGetError() == GL_INVALID_ENUM);
glGetFloatv(GL_SHADER_BINARY_FORMATS, &f);
assert(glGetError() == GL_INVALID_ENUM);