[Mesa-dev] [PATCH 7/7] svga: don't crash/assert if we fail to allocate a vertex buffer

Brian Paul brianp at vmware.com
Thu Nov 10 09:45:20 PST 2011


---
 src/gallium/drivers/svga/svga_swtnl_backend.c |   26 ++++++++++++++++--------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c
index 15b1bb5..e583ad0 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,20 @@ 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);
+      return ptr + svga_render->vbuf_offset;
+   }
+   else {
+      /* we probably ran out of memory when allocating the vertex buffer */
+      return NULL;
+   }
 }
 
 static void
-- 
1.7.3.4



More information about the mesa-dev mailing list