[Mesa-dev] [PATCH] st/mesa: don't crash when clearing non-existant buffers.

Dave Airlie airlied at gmail.com
Thu Jan 5 07:53:18 PST 2012


From: Dave Airlie <airlied at redhat.com>

this fixes the gl3.0 piglit clearbuffer-depth/stencil/invalid buffer
tests for gallium drivers.

only question is should mesa be catching this somewhere higher?

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/state_tracker/st_cb_clear.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 23700ee..1442c6f 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -532,8 +532,9 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
    if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
       /* clearing combined depth + stencil */
       struct st_renderbuffer *strb = st_renderbuffer(depthRb);
-
-      if (strb->surface) {
+      if (!depthRb)
+         mask &= ~BUFFER_BITS_DS;
+      else if (strb->surface) {
          if (check_clear_depth_stencil_with_quad(ctx, depthRb))
             quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
          else
@@ -546,7 +547,9 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
       if (mask & BUFFER_BIT_DEPTH) {
          struct st_renderbuffer *strb = st_renderbuffer(depthRb);
 
-         if (strb->surface) {
+         if (!depthRb)
+            mask &= ~BUFFER_BIT_DEPTH;
+         else if (strb->surface) {
             if (check_clear_depth_with_quad(ctx, depthRb,
                                             st->clear.enable_ds_separate))
                quad_buffers |= PIPE_CLEAR_DEPTH;
@@ -557,7 +560,9 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
       if (mask & BUFFER_BIT_STENCIL) {
          struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
 
-         if (strb->surface) {
+         if (!stencilRb)
+            mask &= ~BUFFER_BIT_STENCIL;
+         else if (strb->surface) {
             if (check_clear_stencil_with_quad(ctx, stencilRb,
                                               st->clear.enable_ds_separate))
                quad_buffers |= PIPE_CLEAR_STENCIL;
-- 
1.7.7.4



More information about the mesa-dev mailing list