Code

deal with the possible failure to create pixblock due to insufficient memory
authorbuliabyak <buliabyak@users.sourceforge.net>
Sat, 14 Oct 2006 17:46:24 +0000 (17:46 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sat, 14 Oct 2006 17:46:24 +0000 (17:46 +0000)
src/display/canvas-arena.cpp
src/display/nr-arena-glyphs.cpp
src/display/nr-arena-shape.cpp
src/display/nr-arena.cpp
src/display/nr-filter-gaussian.cpp
src/display/nr-filter.cpp

index 2d192ac1b222afa98405e5a371d680cb4b458a79..84ed621dbebe904b54a8b7d60a62faee29df16a4 100644 (file)
@@ -279,8 +279,10 @@ sp_canvas_arena_render (SPCanvasItem *item, SPCanvasBuf *buf)
 
 #ifdef STRICT_RGBA
             pb.visible_area = buf->visible_rect; 
-                       nr_arena_item_invoke_render (arena->root, &area, &pb, 0);
-                       nr_blit_pixblock_pixblock (&cb, &pb);
+                       if (pb.data.px != NULL) {
+                           nr_arena_item_invoke_render (arena->root, &area, &pb, 0);
+                           nr_blit_pixblock_pixblock (&cb, &pb);
+                       }
                        nr_pixblock_release (&pb);
 #else
             cb.visible_area = buf->visible_rect; 
index 083e7a7f4a7b35e36179c16cd27f67a970ed1c7d..bd6a5707a064d0ffe0a44edf11b42200d90fae97 100644 (file)
@@ -440,6 +440,13 @@ nr_arena_glyphs_group_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, u
     if (style->fill.type != SP_PAINT_TYPE_NONE || item->arena->rendermode == RENDERMODE_OUTLINE) {
         NRPixBlock m;
         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort 
+        if (m.data.px == NULL) {
+            nr_pixblock_release (&m);
+            return (item->state);
+        }
+
         m.visible_area = pb->visible_area; 
 
         /* Render children fill mask */
@@ -480,6 +487,13 @@ nr_arena_glyphs_group_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, u
         NRPixBlock m;
         guint32 rgba;
         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort 
+        if (m.data.px == NULL) {
+            nr_pixblock_release (&m);
+            return (item->state);
+        }
+
         m.visible_area = pb->visible_area; 
         /* Render children stroke mask */
         for (child = group->children; child != NULL; child = child->next) {
index 2f278b3de56fa9ed92e6e09f2a4d9850c10cee83..32efc527aad177989e55dbf8ca7984f4ad9afe74 100644 (file)
@@ -707,6 +707,13 @@ nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned
         guint32 rgba;
 
         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort render
+        if (m.data.px == NULL) {
+            nr_pixblock_release (&m);
+            return (item->state);
+        }
+
         m.visible_area = pb->visible_area; 
         nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
         m.empty = FALSE;
@@ -738,6 +745,13 @@ nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned
         guint32 rgba;
 
         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort render
+        if (m.data.px == NULL) {
+            nr_pixblock_release (&m);
+            return (item->state);
+        }
+
         m.visible_area = pb->visible_area; 
         nr_pixblock_render_shape_mask_or(m, shape->stroke_shp);
         m.empty = FALSE;
@@ -797,6 +811,13 @@ nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
 
         /* fixme: We can OR in one step (Lauris) */
         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort 
+        if (m.data.px == NULL) {
+            nr_pixblock_release (&m);
+            return (item->state);
+        }
+
         m.visible_area = pb->visible_area; 
         nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
 
index a6e33d2dc43ba743e0340ad5cd2ee4f4629a1105..ba845d1a296b24dc0fa56de18c9ffa5f53d00932 100644 (file)
@@ -109,6 +109,12 @@ nr_arena_render_paintserver_fill (NRPixBlock *pb, NRRectL *area, SPPainter *pain
        NRPixBlock cb, cb_opa;
        nr_pixblock_setup_fast (&cb, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE);
        nr_pixblock_setup_fast (&cb_opa, NR_PIXBLOCK_MODE_R8G8B8A8N, area->x0, area->y0, area->x1, area->y1, TRUE);
+
+        // if memory allocation failed, abort 
+        if (cb.data.px == NULL || cb_opa.data.px == NULL) {
+            return;
+        }
+
     cb.visible_area = pb->visible_area; 
     cb_opa.visible_area = pb->visible_area; 
 
index f54d83816ffac97ddbe3c254cc1fa03f2c003871..d852545ee704f0e5471f7870452378bcc9d5838d 100644 (file)
@@ -281,8 +281,10 @@ int FilterGaussian::render(FilterSlot &slot, Matrix const &trans)
         }
         nr_pixblock_setup_fast(out, in->mode, in->area.x0, in->area.y0,
                                in->area.x1, in->area.y1, true);
-        out->empty = false;
-        slot.set(_output, out);
+        if (out->data.px != NULL) {
+            out->empty = false;
+            slot.set(_output, out);
+        }
         return 0;
     }
 
@@ -315,6 +317,9 @@ int FilterGaussian::render(FilterSlot &slot, Matrix const &trans)
     // set up subsampled buffers
     nr_pixblock_setup_fast(bufx, in->mode, xd0, yd0, xd1, yd1, true);
     nr_pixblock_setup_fast(bufy, in->mode, xd0, yd0, xd1, yd1, true);
+    if (bufx->data.px == NULL || bufy->data.px == NULL) { // no memory
+        return 0;
+    }
 
     //mid->visible_area = in->visible_area;
     //out->visible_area = in->visible_area;
@@ -484,6 +489,10 @@ int FilterGaussian::render(FilterSlot &slot, Matrix const &trans)
     NRPixBlock *out = new NRPixBlock;
     nr_pixblock_setup_fast(out, in->mode, in->area.x0, in->area.y0,
                            in->area.x1, in->area.y1, true);
+    if (out->data.px == NULL) {
+        // alas, we've accomplished a lot, but ran out of memory - so abort
+        return 0;
+    }
 
     for ( int y = yd0 ; y < yd1 - 1; y++ ) {
         for ( int x = xd0 ; x < xd1 - 1; x++ ) {
index 03c92fff3626b5863f02b7b4d3552ef8c1ac7549..346e61686a3ffe460b511693602cfffa5b5d14b5 100644 (file)
@@ -116,6 +116,8 @@ int Filter::render(NRArenaItem const *item, NRPixBlock *pb)
         }
         if (y_len < 1) y_len = 1;
         nr_pixblock_setup_fast(in, pb->mode, 0, 0, x_len, y_len, true);
+        if (in->data.px == NULL) // memory allocation failed
+            return 0;
         scale_bicubic(in, pb);
         scale res_scaling(x_len / (double)(pb->area.x1 - pb->area.x0),
                           y_len / (double)(pb->area.y1 - pb->area.y0));
@@ -125,6 +127,8 @@ int Filter::render(NRArenaItem const *item, NRPixBlock *pb)
         nr_pixblock_setup_fast(in, pb->mode,
                                pb->area.x0, pb->area.y0,
                                pb->area.x1, pb->area.y1, true);
+        if (in->data.px == NULL) // memory allocation failed
+            return 0;
         nr_blit_pixblock_pixblock(in, pb);
     }
     slot.set(NR_FILTER_SOURCEGRAPHIC, in);