llvmpipe: Make more resilient to out-of-memory situations.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 9 Nov 2011 19:29:37 +0000 (19:29 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 3 Feb 2012 18:51:14 +0000 (18:51 +0000)
Most of the code was alright, but we were missing a few paths.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/llvmpipe/lp_texture.c

index 8fac77b0c57d6dc4bc9af21b36853e604f6884a7..e895485e9476264bcf25e03295aa92a8d4637fc8 100644 (file)
@@ -978,7 +978,9 @@ alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
       /* tiled data is stored in regular memory */
       uint buffer_size = tex_image_size(lpr, level, layout);
       lpr->tiled[level].data = align_malloc(buffer_size, alignment);
-      memset(lpr->tiled[level].data, 0, buffer_size);
+      if (lpr->tiled[level].data) {
+         memset(lpr->tiled[level].data, 0, buffer_size);
+      }
    }
    else {
       assert(layout == LP_TEX_LAYOUT_LINEAR);
@@ -997,7 +999,9 @@ alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
          /* not a display target - allocate regular memory */
          uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
          lpr->linear[level].data = align_malloc(buffer_size, alignment);
-         memset(lpr->linear[level].data, 0, buffer_size);
+         if (lpr->linear[level].data) {
+            memset(lpr->linear[level].data, 0, buffer_size);
+         }
       }
    }
 }