From: buliabyak Date: Sat, 14 Oct 2006 17:46:24 +0000 (+0000) Subject: deal with the possible failure to create pixblock due to insufficient memory X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=82434ebeb8b89c923ea69cc039eb482623078e38;p=inkscape.git deal with the possible failure to create pixblock due to insufficient memory --- diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index 2d192ac1b..84ed621db 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -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; diff --git a/src/display/nr-arena-glyphs.cpp b/src/display/nr-arena-glyphs.cpp index 083e7a7f4..bd6a5707a 100644 --- a/src/display/nr-arena-glyphs.cpp +++ b/src/display/nr-arena-glyphs.cpp @@ -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) { diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index 2f278b3de..32efc527a 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -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); diff --git a/src/display/nr-arena.cpp b/src/display/nr-arena.cpp index a6e33d2dc..ba845d1a2 100644 --- a/src/display/nr-arena.cpp +++ b/src/display/nr-arena.cpp @@ -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; diff --git a/src/display/nr-filter-gaussian.cpp b/src/display/nr-filter-gaussian.cpp index f54d83816..d852545ee 100644 --- a/src/display/nr-filter-gaussian.cpp +++ b/src/display/nr-filter-gaussian.cpp @@ -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++ ) { diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index 03c92fff3..346e61686 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -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);