llvmpipe: don't crash/assert on out of memory
authorBrian Paul <brianp@vmware.com>
Tue, 29 Jun 2010 21:40:15 +0000 (15:40 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 29 Jun 2010 21:40:19 +0000 (15:40 -0600)
Check for null pointers and return early, etc.

src/gallium/drivers/llvmpipe/lp_rast_priv.h
src/gallium/drivers/llvmpipe/lp_surface.c
src/gallium/drivers/llvmpipe/lp_texture.c

index d33dd49f3a7dba7d4bf13bc7afdafaea80301b21..9bded086efcfb48805b9f29ba91aad323262a34f 100644 (file)
@@ -172,7 +172,8 @@ lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,
    assert((y % TILE_VECTOR_HEIGHT) == 0);
 
    color = task->color_tiles[buf];
-   assert(color);
+   if (!color)
+      return NULL;
 
    px = x % TILE_SIZE;
    py = y % TILE_SIZE;
index f0cbbe8c56098ce74308e082f07f379a7be59da3..f761e8285000b2adea39f26bdfe5b658791ef4ab 100644 (file)
@@ -146,13 +146,15 @@ lp_resource_copy(struct pipe_context *pipe,
                                               subdst.level,
                                               LP_TEX_LAYOUT_LINEAR);
 
-      util_copy_rect(dst_linear_ptr, format,
-                     llvmpipe_resource_stride(&dst_tex->base, subdst.level),
-                     dstx, dsty,
-                     width, height,
-                     src_linear_ptr,
-                     llvmpipe_resource_stride(&src_tex->base, subsrc.level),
-                     srcx, srcy);
+      if (dst_linear_ptr && src_linear_ptr) {
+         util_copy_rect(dst_linear_ptr, format,
+                        llvmpipe_resource_stride(&dst_tex->base, subdst.level),
+                        dstx, dsty,
+                        width, height,
+                        src_linear_ptr,
+                        llvmpipe_resource_stride(&src_tex->base, subsrc.level),
+                        srcx, srcy);
+      }
    }
 }
 
index 0d526ead89d229abb81ca70df4c47da139d98da1..a156bb6517bd072a0d708504bb6e512ebecec0c1 100644 (file)
@@ -389,7 +389,6 @@ llvmpipe_resource_map(struct pipe_resource *resource,
 
       map = llvmpipe_get_texture_image(lpr, face + zslice, level,
                                        tex_usage, layout);
-      assert(map);
       return map;
    }
    else {
@@ -1035,7 +1034,7 @@ llvmpipe_get_texture_image(struct llvmpipe_resource *lpr,
 
             layout_logic(cur_layout, layout, usage, &new_layout, &convert);
 
-            if (convert) {
+            if (convert && other_data && target_data) {
                if (layout == LP_TEX_LAYOUT_TILED) {
                   lp_linear_to_tiled(other_data, target_data,
                                      x * TILE_SIZE, y * TILE_SIZE,
@@ -1067,8 +1066,6 @@ llvmpipe_get_texture_image(struct llvmpipe_resource *lpr,
                                         width_t, height_t, layout);
    }
 
-   assert(target_data);
-
    return target_data;
 }
 
@@ -1187,13 +1184,16 @@ llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr,
    cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
 
    layout_logic(cur_layout, LP_TEX_LAYOUT_TILED, usage, &new_layout, &convert);
-   if (convert) {
+   if (convert && linear_image && tiled_image) {
       lp_linear_to_tiled(linear_image, tiled_image,
                          x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
                          lpr->row_stride[level],
                          lpr->tiles_per_row[level]);
    }
 
+   if (!tiled_image)
+      return NULL;
+
    if (new_layout != cur_layout)
       llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);