util/upload: catch failures to map_range and return error
authorKeith Whitwell <keithw@vmware.com>
Thu, 7 May 2009 08:24:37 +0000 (09:24 +0100)
committerKeith Whitwell <keithw@vmware.com>
Fri, 8 May 2009 13:57:30 +0000 (14:57 +0100)
Caller may be able to do something about this - eg flush and retry.

src/gallium/auxiliary/util/u_upload_mgr.c

index d9c0d7afa89d6fb86effc373899baa66686b261b..2eb98068c86ac799689131eb2f06675fca1237a9 100644 (file)
@@ -70,7 +70,7 @@ struct u_upload_mgr *u_upload_create( struct pipe_screen *screen,
 }
 
 
-static INLINE void
+static INLINE enum pipe_error
 my_buffer_write(struct pipe_screen *screen,
                 struct pipe_buffer *buf,
                 unsigned offset, unsigned size, unsigned dirty_size,
@@ -84,12 +84,14 @@ my_buffer_write(struct pipe_screen *screen,
    assert(size);
 
    map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE);
-   assert(map);
-   if(map) {
-      memcpy(map + offset, data, size);
-      pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
-      pipe_buffer_unmap(screen, buf);
-   }
+   if (map == NULL) 
+      return PIPE_ERROR_OUT_OF_MEMORY;
+
+   memcpy(map + offset, data, size);
+   pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
+   pipe_buffer_unmap(screen, buf);
+
+   return PIPE_OK;
 }
 
 /* Release old buffer.
@@ -162,12 +164,14 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload,
 
    /* Copy the data, using map_range if available:
     */
-   my_buffer_write( upload->screen, 
-                    upload->buffer,
-                    upload->offset,
-                    size, 
-                    alloc_size,
-                    data );
+   ret = my_buffer_write( upload->screen, 
+                          upload->buffer,
+                          upload->offset,
+                          size, 
+                          alloc_size,
+                          data );
+   if (ret)
+      return ret;
 
    /* Emit the return values:
     */