st/mesa: do proper error checking for u_upload_alloc() calls
authorBrian Paul <brianp@vmware.com>
Thu, 24 Jan 2013 21:51:05 +0000 (14:51 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 25 Jan 2013 22:41:40 +0000 (15:41 -0700)
We weren't properly checking the return value of these calls (and
calls to u_upload_data()) to detect OOM errors.

Note: This is a candidate for the 9.0 branch.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_drawtex.c
src/mesa/state_tracker/st_draw.c

index 843dc5be33715a345155536b0068deda4e0ee690..63dbdb29be31cc027f923d9a285ebe7bafcb5f6b 100644 (file)
@@ -350,9 +350,8 @@ setup_bitmap_vertex_data(struct st_context *st, bool normalized,
       tBot = (GLfloat) height;
    }
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), vbuf_offset, vbuf,
-                 (void**)&vertices);
-   if (!vbuf) {
+   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
+                      vbuf_offset, vbuf, (void **) &vertices) != PIPE_OK) {
       return;
    }
 
index d01236e280624f0476b1eeca6656b55c56f23694..a5aa8f496028ed2ceb9b07b17998057d97ad872c 100644 (file)
@@ -141,9 +141,8 @@ draw_quad(struct st_context *st,
    GLuint i, offset;
    float (*vertices)[2][4];  /**< vertex pos + color */
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), &offset, &vbuf,
-                 (void**)&vertices);
-   if (!vbuf) {
+   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
+                      &offset, &vbuf, (void **) &vertices) != PIPE_OK) {
       return;
    }
 
index 65f116083a94b0f55a54625d307dedbfc703500c..c944b81f690674e905202557f5a5f282f0d4d5ba 100644 (file)
@@ -568,9 +568,8 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
    struct pipe_resource *buf = NULL;
    unsigned offset;
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset, &buf,
-                 (void**)&verts);
-   if (!buf) {
+   if (u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset,
+                      &buf, (void **) &verts) != PIPE_OK) {
       return;
    }
 
index 269068da2b0a407b92ccccd4ccde093bdc6a1068..5ca097004532d8ea7bb1cec495da79a9fffb2fbd 100644 (file)
@@ -148,10 +148,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
       GLfloat *vbuf = NULL;
       GLuint attr;
 
-      u_upload_alloc(st->uploader, 0,
-                    numAttribs * 4 * 4 * sizeof(GLfloat),
-                    &offset, &vbuffer, (void**)&vbuf);
-      if (!vbuffer) {
+      if (u_upload_alloc(st->uploader, 0,
+                         numAttribs * 4 * 4 * sizeof(GLfloat),
+                         &offset, &vbuffer, (void **) &vbuf) != PIPE_OK) {
          return;
       }
       
index de539ca5a6f64ecb11b8290507552ea8cac0eb2d..de62264a16cdee84c3f48c086fc5a0fe2180a3f7 100644 (file)
@@ -84,7 +84,12 @@ all_varyings_in_vbos(const struct gl_client_array *arrays[])
 }
 
 
-static void
+/**
+ * Basically, translate Mesa's index buffer information into
+ * a pipe_index_buffer object.
+ * \return TRUE or FALSE for success/failure
+ */
+static boolean
 setup_index_buffer(struct st_context *st,
                    const struct _mesa_index_buffer *ib,
                    struct pipe_index_buffer *ibuffer)
@@ -100,8 +105,12 @@ setup_index_buffer(struct st_context *st,
       ibuffer->offset = pointer_to_offset(ib->ptr);
    }
    else if (st->indexbuf_uploader) {
-      u_upload_data(st->indexbuf_uploader, 0, ib->count * ibuffer->index_size,
-                    ib->ptr, &ibuffer->offset, &ibuffer->buffer);
+      if (u_upload_data(st->indexbuf_uploader, 0,
+                        ib->count * ibuffer->index_size, ib->ptr,
+                        &ibuffer->offset, &ibuffer->buffer) != PIPE_OK) {
+         /* out of memory */
+         return FALSE;
+      }
       u_upload_unmap(st->indexbuf_uploader);
    }
    else {
@@ -110,6 +119,7 @@ setup_index_buffer(struct st_context *st,
    }
 
    cso_set_index_buffer(st->cso_context, ibuffer);
+   return TRUE;
 }
 
 
@@ -220,7 +230,10 @@ st_draw_vbo(struct gl_context *ctx,
             vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index,
                                    nr_prims);
 
-      setup_index_buffer(st, ib, &ibuffer);
+      if (!setup_index_buffer(st, ib, &ibuffer)) {
+         /* out of memory */
+         return;
+      }
 
       info.indexed = TRUE;
       if (min_index != ~0 && max_index != ~0) {