Fix trying to clear nonexistent FBO attachments
The D3D11 backend used to crash to a null pointer dereference if a
glClearBuffer call was done on a nonexistent depth or stencil
attachment. Validate for these conditions so that the backend can't
crash in this case.
BUG=angleproject:2827
TEST=angle_end2end_tests
Change-Id: Iecee78d213d11d492d52f246b4b068e8b6f34244
Reviewed-on: https://chromium-review.googlesource.com/1233675
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index cb1c678..f9b1fe7 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -3534,6 +3534,11 @@
void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
{
+ if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
+ {
+ // It's not an error to try to clear a non-existent depth buffer, but it's a no-op.
+ return;
+ }
ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
ANGLE_CONTEXT_TRY(
mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
@@ -3548,6 +3553,11 @@
void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
{
+ if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
+ {
+ // It's not an error to try to clear a non-existent stencil buffer, but it's a no-op.
+ return;
+ }
ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
ANGLE_CONTEXT_TRY(
mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));