2.0 Translator:GL_INVALID_VALUE on bad program/shader
The getGlobalName function returns 0 on error. There are many places
were no error checking is done after calling it to get a shader or
program name. Typically this shouldn't be an issue, since the follwing
OpenGL call using a value of 0 will generated the required GL_INVALID_VALUE,
but this does not always happen.
Change-Id: I8edf2b152978ffd8626f8b4d778cc624f2a3bec3
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
index d1f6a99..29dd5c7 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
@@ -125,7 +125,9 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
+ SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
ctx->dispatcher().glAttachShader(globalProgramName,globalShaderName);
}
}
@@ -134,6 +136,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glBindAttribLocation(globalProgramName,index,name);
}
}
@@ -278,6 +281,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
+ SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
ctx->dispatcher().glCompileShader(globalShaderName);
}
}
@@ -430,7 +434,9 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
+ SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
ctx->dispatcher().glDetachShader(globalProgramName,globalShaderName);
}
}
@@ -605,6 +611,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetActiveAttrib(globalProgramName,index,bufsize,length,size,type,name);
}
}
@@ -613,6 +620,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetActiveUniform(globalProgramName,index,bufsize,length,size,type,name);
}
}
@@ -621,6 +629,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetAttachedShaders(globalProgramName,maxcount,count,shaders);
for(int i=0 ; i < *count ;i++){
shaders[i] = thrd->shareGroup->getLocalName(SHADER,shaders[i]);
@@ -632,6 +641,7 @@
GET_CTX_RET(-1);
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1);
return ctx->dispatcher().glGetAttribLocation(globalProgramName,name);
}
return -1;
@@ -847,6 +857,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetProgramiv(globalProgramName,pname,params);
}
}
@@ -855,6 +866,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetProgramInfoLog(globalProgramName,bufsize,length,infolog);
}
}
@@ -863,6 +875,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
+ SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetShaderiv(globalShaderName,pname,params);
}
}
@@ -871,6 +884,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shader);
+ SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetShaderInfoLog(globalShaderName,bufsize,length,infolog);
}
}
@@ -962,6 +976,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetUniformfv(globalProgramName,location,params);
}
}
@@ -970,6 +985,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glGetUniformiv(globalProgramName,location,params);
}
}
@@ -978,6 +994,7 @@
GET_CTX_RET(-1);
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1);
return ctx->dispatcher().glGetUniformLocation(globalProgramName,name);
}
return -1;
@@ -1140,6 +1157,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glLinkProgram(globalProgramName);
}
}
@@ -1197,6 +1215,7 @@
if(thrd->shareGroup.Ptr()){
for(int i=0; i < n ; i++){
const GLuint globalShaderName = thrd->shareGroup->getGlobalName(SHADER,shaders[i]);
+ SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE);
ctx->dispatcher().glShaderBinary(1,&globalShaderName,binaryformat,binary,length);
}
}
@@ -1420,6 +1439,7 @@
GET_CTX();
if(thrd->shareGroup.Ptr()) {
const GLuint globalProgramName = thrd->shareGroup->getGlobalName(SHADER,program);
+ SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE);
ctx->dispatcher().glValidateProgram(globalProgramName);
}
}