st/mesa: don't unreference user attribs up front.
authorDave Airlie <airlied@redhat.com>
Thu, 9 Feb 2012 19:44:55 +0000 (19:44 +0000)
committerDave Airlie <airlied@redhat.com>
Tue, 28 Feb 2012 10:33:06 +0000 (10:33 +0000)
postpone unreferences until end of function, as the ones in use will
get naturally dereferenced.

Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/mesa/state_tracker/st_draw.c

index c0554cfc70a5b664cfc931651d0bdb99416c1129..c4b2caccdc3de1d323136efd5e2150ea77a48a51 100644 (file)
@@ -905,6 +905,7 @@ st_validate_varrays(struct gl_context *ctx,
    unsigned num_vbuffers, num_velements;
    GLuint attr;
    unsigned i;
+   unsigned old_num_user_attribs;
 
    /* must get these after state validation! */
    vp = st->vp;
@@ -913,9 +914,7 @@ st_validate_varrays(struct gl_context *ctx,
    memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
 
    /* Unreference any user vertex buffers. */
-   for (i = 0; i < st->num_user_attribs; i++) {
-      pipe_resource_reference(&st->user_attrib[i].buffer, NULL);
-   }
+   old_num_user_attribs = st->num_user_attribs;
    st->num_user_attribs = 0;
 
    /*
@@ -954,6 +953,10 @@ st_validate_varrays(struct gl_context *ctx,
       assert(!vbuffer[attr].buffer);
    }
 
+   for (i = old_num_user_attribs; i < st->num_user_attribs; i++) {
+      pipe_resource_reference(&st->user_attrib[i].buffer, NULL);
+   }
+
    return GL_TRUE;
 }