draw: handle some out of memory conditions
authorAlan Hourihane <alanh@vmware.com>
Wed, 16 Jun 2010 11:27:20 +0000 (12:27 +0100)
committerAlan Hourihane <alanh@vmware.com>
Wed, 16 Jun 2010 11:27:53 +0000 (12:27 +0100)
12 files changed:
src/gallium/auxiliary/draw/draw_pipe_aaline.c
src/gallium/auxiliary/draw/draw_pipe_aapoint.c
src/gallium/auxiliary/draw/draw_pipe_clip.c
src/gallium/auxiliary/draw/draw_pipe_cull.c
src/gallium/auxiliary/draw/draw_pipe_flatshade.c
src/gallium/auxiliary/draw/draw_pipe_offset.c
src/gallium/auxiliary/draw/draw_pipe_pstipple.c
src/gallium/auxiliary/draw/draw_pipe_stipple.c
src/gallium/auxiliary/draw/draw_pipe_twoside.c
src/gallium/auxiliary/draw/draw_pipe_unfilled.c
src/gallium/auxiliary/draw/draw_pipe_wide_line.c
src/gallium/auxiliary/draw/draw_pipe_wide_point.c

index 4faf0a779caa11fb542d6906bd340205711b02a5..debd17fd74b0bf53de7ebf36dc9e3093f7ba6b8c 100644 (file)
@@ -788,9 +788,6 @@ draw_aaline_stage(struct draw_context *draw)
    if (aaline == NULL)
       return NULL;
 
-   if (!draw_alloc_temp_verts( &aaline->stage, 8 ))
-      goto fail;
-
    aaline->stage.draw = draw;
    aaline->stage.name = "aaline";
    aaline->stage.next = NULL;
@@ -801,11 +798,14 @@ draw_aaline_stage(struct draw_context *draw)
    aaline->stage.reset_stipple_counter = aaline_reset_stipple_counter;
    aaline->stage.destroy = aaline_destroy;
 
+   if (!draw_alloc_temp_verts( &aaline->stage, 8 ))
+      goto fail;
+
    return aaline;
 
  fail:
    if (aaline)
-      aaline_destroy(&aaline->stage);
+      aaline->stage.destroy(&aaline->stage);
 
    return NULL;
 }
index bba6f50c0207709658bc0d1bc3524ac685132fbb..d406a86ccb537c601234c2c8c0c2924ad82dc54b 100644 (file)
@@ -780,9 +780,6 @@ draw_aapoint_stage(struct draw_context *draw)
    if (aapoint == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &aapoint->stage, 4 ))
-      goto fail;
-
    aapoint->stage.draw = draw;
    aapoint->stage.name = "aapoint";
    aapoint->stage.next = NULL;
@@ -793,11 +790,14 @@ draw_aapoint_stage(struct draw_context *draw)
    aapoint->stage.reset_stipple_counter = aapoint_reset_stipple_counter;
    aapoint->stage.destroy = aapoint_destroy;
 
+   if (!draw_alloc_temp_verts( &aapoint->stage, 4 ))
+      goto fail;
+
    return aapoint;
 
  fail:
    if (aapoint)
-      aapoint_destroy(&aapoint->stage);
+      aapoint->stage.destroy(&aapoint->stage);
 
    return NULL;
 
index df8d82e367d814e24e44579883ce2c0d6408d200..122b1c796895a3513711f3c1513d8f9c6695e089 100644 (file)
@@ -522,9 +522,6 @@ struct draw_stage *draw_clip_stage( struct draw_context *draw )
    if (clipper == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 ))
-      goto fail;
-
    clipper->stage.draw = draw;
    clipper->stage.name = "clipper";
    clipper->stage.point = clip_point;
@@ -536,6 +533,9 @@ struct draw_stage *draw_clip_stage( struct draw_context *draw )
 
    clipper->plane = draw->plane;
 
+   if (!draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 ))
+      goto fail;
+
    return &clipper->stage;
 
  fail:
index bf84ce30ed1cf3aabeaf45b497a8909cea7525e5..2f4d01d23ab0ad4aaf078135db0f7195a30f20dd 100644 (file)
@@ -129,9 +129,6 @@ struct draw_stage *draw_cull_stage( struct draw_context *draw )
    if (cull == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &cull->stage, 0 ))
-      goto fail;
-
    cull->stage.draw = draw;
    cull->stage.name = "cull";
    cull->stage.next = NULL;
@@ -142,6 +139,9 @@ struct draw_stage *draw_cull_stage( struct draw_context *draw )
    cull->stage.reset_stipple_counter = cull_reset_stipple_counter;
    cull->stage.destroy = cull_destroy;
 
+   if (!draw_alloc_temp_verts( &cull->stage, 0 ))
+      goto fail;
+
    return &cull->stage;
 
 fail:
index 34afb1a0b609bdb82a18fd6af9d269190bf6c0df..693f2895aad9232a21fb7152fb5c1cb0ae0d664f 100644 (file)
@@ -257,9 +257,6 @@ struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
    if (flatshade == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &flatshade->stage, 2 ))
-      goto fail;
-
    flatshade->stage.draw = draw;
    flatshade->stage.name = "flatshade";
    flatshade->stage.next = NULL;
@@ -270,6 +267,9 @@ struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
    flatshade->stage.reset_stipple_counter = flatshade_reset_stipple_counter;
    flatshade->stage.destroy = flatshade_destroy;
 
+   if (!draw_alloc_temp_verts( &flatshade->stage, 2 ))
+      goto fail;
+
    return &flatshade->stage;
 
  fail:
index 8e321946ceda7b7dff528563d27c1c36ef7acd88..8afbbfa1569c026ee25dc3ab6e187e18407b0218 100644 (file)
@@ -161,9 +161,7 @@ struct draw_stage *draw_offset_stage( struct draw_context *draw )
 {
    struct offset_stage *offset = CALLOC_STRUCT(offset_stage);
    if (offset == NULL)
-      return NULL;
-
-   draw_alloc_temp_verts( &offset->stage, 3 );
+      goto fail;
 
    offset->stage.draw = draw;
    offset->stage.name = "offset";
@@ -175,5 +173,14 @@ struct draw_stage *draw_offset_stage( struct draw_context *draw )
    offset->stage.reset_stipple_counter = offset_reset_stipple_counter;
    offset->stage.destroy = offset_destroy;
 
+   if (!draw_alloc_temp_verts( &offset->stage, 3 ))
+      goto fail;
+
    return &offset->stage;
+
+fail:
+   if (offset)
+      offset->stage.destroy( &offset->stage );
+
+   return NULL;
 }
index ef30db094fea9af3a6c67af64b6a71478cbafcce..fff960c7eb5ea726c0be84b3e60fe43c58098971 100644 (file)
@@ -607,8 +607,8 @@ static struct pstip_stage *
 draw_pstip_stage(struct draw_context *draw)
 {
    struct pstip_stage *pstip = CALLOC_STRUCT(pstip_stage);
-
-   draw_alloc_temp_verts( &pstip->stage, 8 );
+   if (pstip == NULL)
+      goto fail;
 
    pstip->stage.draw = draw;
    pstip->stage.name = "pstip";
@@ -620,7 +620,16 @@ draw_pstip_stage(struct draw_context *draw)
    pstip->stage.reset_stipple_counter = pstip_reset_stipple_counter;
    pstip->stage.destroy = pstip_destroy;
 
+   if (!draw_alloc_temp_verts( &pstip->stage, 8 ))
+      goto fail;
+
    return pstip;
+
+fail:
+   if (pstip)
+      pstip->stage.destroy( &pstip->stage );
+
+   return NULL;
 }
 
 
index 70fbab9ea7673dca3cbdf1a1162dd4fb0a6caaff..4b3f4e7ae1169d9647d53ec762c061341d92c569 100644 (file)
@@ -235,8 +235,8 @@ stipple_destroy( struct draw_stage *stage )
 struct draw_stage *draw_stipple_stage( struct draw_context *draw )
 {
    struct stipple_stage *stipple = CALLOC_STRUCT(stipple_stage);
-
-   draw_alloc_temp_verts( &stipple->stage, 2 );
+   if (stipple == NULL)
+      goto fail;
 
    stipple->stage.draw = draw;
    stipple->stage.name = "stipple";
@@ -248,5 +248,14 @@ struct draw_stage *draw_stipple_stage( struct draw_context *draw )
    stipple->stage.flush = stipple_flush;
    stipple->stage.destroy = stipple_destroy;
 
+   if (!draw_alloc_temp_verts( &stipple->stage, 2 ))
+      goto fail;
+
    return &stipple->stage;
+
+fail:
+   if (stipple)
+      stipple->stage.destroy( &stipple->stage );
+
+   return NULL;
 }
index 808b2fb0b58611a1d2fc7013a2ff4c83d1ea8621..9a3f3fee625c793b513761b5d185eb7c8e7ff1b1 100644 (file)
@@ -177,9 +177,6 @@ struct draw_stage *draw_twoside_stage( struct draw_context *draw )
    if (twoside == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &twoside->stage, 3 ))
-      goto fail;
-
    twoside->stage.draw = draw;
    twoside->stage.name = "twoside";
    twoside->stage.next = NULL;
@@ -190,6 +187,9 @@ struct draw_stage *draw_twoside_stage( struct draw_context *draw )
    twoside->stage.reset_stipple_counter = twoside_reset_stipple_counter;
    twoside->stage.destroy = twoside_destroy;
 
+   if (!draw_alloc_temp_verts( &twoside->stage, 3 ))
+      goto fail;
+
    return &twoside->stage;
 
  fail:
index e333d26a9320a8775203490dff252a057f059849..d87741b91e7ce5c821c2e617a409a8076e7b1c5a 100644 (file)
@@ -202,9 +202,6 @@ struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
    if (unfilled == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &unfilled->stage, 0 ))
-      goto fail;
-
    unfilled->stage.draw = draw;
    unfilled->stage.name = "unfilled";
    unfilled->stage.next = NULL;
@@ -216,6 +213,9 @@ struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
    unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
    unfilled->stage.destroy = unfilled_destroy;
 
+   if (!draw_alloc_temp_verts( &unfilled->stage, 0 ))
+      goto fail;
+
    return &unfilled->stage;
 
  fail:
index d7ac95b740510b9990a8fd9f9dc76891d3fb0c15..98da9cfb999c8dd25abe484c19735c1716ba3082 100644 (file)
@@ -202,8 +202,8 @@ static void wideline_destroy( struct draw_stage *stage )
 struct draw_stage *draw_wide_line_stage( struct draw_context *draw )
 {
    struct wideline_stage *wide = CALLOC_STRUCT(wideline_stage);
-
-   draw_alloc_temp_verts( &wide->stage, 4 );
+   if (wide == NULL)
+      goto fail;
 
    wide->stage.draw = draw;
    wide->stage.name = "wide-line";
@@ -215,5 +215,14 @@ struct draw_stage *draw_wide_line_stage( struct draw_context *draw )
    wide->stage.reset_stipple_counter = wideline_reset_stipple_counter;
    wide->stage.destroy = wideline_destroy;
 
+   if (!draw_alloc_temp_verts( &wide->stage, 4 ))
+      goto fail;
+
    return &wide->stage;
+
+fail:
+   if (wide)
+      wide->stage.destroy( &wide->stage );
+
+   return NULL;
 }
index a86fe19586ceb5488d5e92b8f718d9f596605cbf..3e6e5389950779a0b543faf377864ea6c2dc278e 100644 (file)
@@ -324,9 +324,6 @@ struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
    if (wide == NULL)
       goto fail;
 
-   if (!draw_alloc_temp_verts( &wide->stage, 4 ))
-      goto fail;
-
    wide->stage.draw = draw;
    wide->stage.name = "wide-point";
    wide->stage.next = NULL;
@@ -337,6 +334,9 @@ struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
    wide->stage.reset_stipple_counter = widepoint_reset_stipple_counter;
    wide->stage.destroy = widepoint_destroy;
 
+   if (!draw_alloc_temp_verts( &wide->stage, 4 ))
+      goto fail;
+
    return &wide->stage;
 
  fail: