summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2011-11-10 09:54:26 -0700
committerBrian Paul <[email protected]>2011-11-11 07:10:56 -0700
commit871dc64869fa371debf03735e215a12cf2ec1742 (patch)
treefff8a55a34557ac93871f5909087e7fa17f4175e /src/gallium/drivers
parentaa661306828b8c76c1511f05e0fae577f06477b8 (diff)
svga: don't crash/assert if we fail to allocate a vertex buffer
v2: check if pipe_buffer_map() returns NULL, and return NULL from svga_vbuf_render_map_vertices(). Per Jose's suggestion. Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/svga/svga_swtnl_backend.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c
index 15b1bb5e097..e149d21a47e 100644
--- a/src/gallium/drivers/svga/svga_swtnl_backend.c
+++ b/src/gallium/drivers/svga/svga_swtnl_backend.c
@@ -96,7 +96,9 @@ svga_vbuf_render_allocate_vertices( struct vbuf_render *render,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STREAM,
svga_render->vbuf_size);
- assert(svga_render->vbuf);
+ /* The buffer allocation may fail if we run out of memory.
+ * The draw module's vbuf code should handle that without crashing.
+ */
}
svga->swtnl.new_vdecl = TRUE;
@@ -119,14 +121,23 @@ svga_vbuf_render_map_vertices( struct vbuf_render *render )
struct svga_vbuf_render *svga_render = svga_vbuf_render(render);
struct svga_context *svga = svga_render->svga;
- char *ptr = (char*)pipe_buffer_map(&svga->pipe,
- svga_render->vbuf,
- PIPE_TRANSFER_WRITE |
- PIPE_TRANSFER_FLUSH_EXPLICIT |
- PIPE_TRANSFER_DISCARD |
- PIPE_TRANSFER_UNSYNCHRONIZED,
- &svga_render->vbuf_transfer);
- return ptr + svga_render->vbuf_offset;
+ if (svga_render->vbuf) {
+ char *ptr = (char*)pipe_buffer_map(&svga->pipe,
+ svga_render->vbuf,
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_FLUSH_EXPLICIT |
+ PIPE_TRANSFER_DISCARD |
+ PIPE_TRANSFER_UNSYNCHRONIZED,
+ &svga_render->vbuf_transfer);
+ if (ptr)
+ return ptr + svga_render->vbuf_offset;
+ else
+ return NULL;
+ }
+ else {
+ /* we probably ran out of memory when allocating the vertex buffer */
+ return NULL;
+ }
}
static void