Vertex Array Object crash fix Vertex array objects are not allocated when generated, but only when bound, so it's legal to have a null vertex array object internally. Change-Id: Ib28a388939e285425c09cfbc9f4efef3f4a8cead Reviewed-on: https://swiftshader-review.googlesource.com/4700 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp index 04ec7f8..237a8a6 100644 --- a/src/OpenGL/libGLESv2/Context.cpp +++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -1536,6 +1536,13 @@ return getVertexArray(mState.vertexArray); } +bool Context::isVertexArray(GLuint array) const +{ + VertexArrayMap::const_iterator vertexArray = mVertexArrayMap.find(array); + + return vertexArray != mVertexArrayMap.end(); +} + bool Context::hasZeroDivisor() const { // Verify there is at least one active attribute with a divisor of zero @@ -3642,7 +3649,11 @@ for(auto vaoIt = mVertexArrayMap.begin(); vaoIt != mVertexArrayMap.end(); vaoIt++) { - vaoIt->second->detachBuffer(buffer); + VertexArray* vertexArray = vaoIt->second; + if(vertexArray) + { + vertexArray->detachBuffer(buffer); + } } for(int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h index cf06cfb..73f7358 100644 --- a/src/OpenGL/libGLESv2/Context.h +++ b/src/OpenGL/libGLESv2/Context.h
@@ -601,6 +601,7 @@ Query *getQuery(GLuint handle) const; VertexArray *getVertexArray(GLuint array) const; VertexArray *getCurrentVertexArray() const; + bool isVertexArray(GLuint array) const; TransformFeedback *getTransformFeedback(GLuint transformFeedback) const; TransformFeedback *getTransformFeedback() const; Sampler *getSampler(GLuint sampler) const;
diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp index 5e5dc4d..dcea67b 100644 --- a/src/OpenGL/libGLESv2/libGLESv3.cpp +++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -1743,7 +1743,7 @@ if(context) { - if(!context->getVertexArray(array)) + if(!context->isVertexArray(array)) { return error(GL_INVALID_OPERATION); }