draw: propogate lots of errors
authorKeith Whitwell <keith@tungstengraphics.com>
Mon, 21 Apr 2008 16:03:37 +0000 (17:03 +0100)
committerKeith Whitwell <keith@tungstengraphics.com>
Mon, 21 Apr 2008 16:03:37 +0000 (17:03 +0100)
17 files changed:
src/gallium/auxiliary/draw/draw_context.h
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_twoside.c
src/gallium/auxiliary/draw/draw_pipe_unfilled.c
src/gallium/auxiliary/draw/draw_pipe_util.c
src/gallium/auxiliary/draw/draw_pipe_validate.c
src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_pipe_wide_point.c
src/gallium/auxiliary/draw/draw_pt_fetch_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
src/gallium/auxiliary/draw/draw_pt_vcache.c

index 197235b2d85faf995f8ab9b216e7acd1e2d83257..274200169878cd41409d51f4c3b5141c4a599230 100644 (file)
@@ -79,7 +79,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe);
 boolean
 draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe);
 
-void
+boolean
 draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe);
 
 
index bc514d40f069d6794c8bb81308b4d9879f27f32a..fbb5b45b40376b10670a797e53d53743c42b170d 100644 (file)
@@ -765,13 +765,13 @@ aaline_create_fs_state(struct pipe_context *pipe,
 {
    struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
    struct aaline_fragment_shader *aafs = CALLOC_STRUCT(aaline_fragment_shader);
+   if (aafs == NULL)
+      return NULL;
 
-   if (aafs) {
-      aafs->state = *fs;
+   aafs->state = *fs;
 
-      /* pass-through */
-      aafs->driver_fs = aaline->driver_create_fs_state(aaline->pipe, fs);
-   }
+   /* pass-through */
+   aafs->driver_fs = aaline->driver_create_fs_state(aaline->pipe, fs);
 
    return aafs;
 }
index 6d689c36de6cbea51e0d01e5b212bd42d729a8c7..ac0aa4cd7ce02adcb955c5e2cb35551dce21f082 100644 (file)
@@ -783,13 +783,13 @@ aapoint_create_fs_state(struct pipe_context *pipe,
 {
    struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe);
    struct aapoint_fragment_shader *aafs = CALLOC_STRUCT(aapoint_fragment_shader);
+   if (aafs == NULL) 
+      return NULL;
 
-   if (aafs) {
-      aafs->state = *fs;
+   aafs->state = *fs;
 
-      /* pass-through */
-      aafs->driver_fs = aapoint->driver_create_fs_state(aapoint->pipe, fs);
-   }
+   /* pass-through */
+   aafs->driver_fs = aapoint->driver_create_fs_state(aapoint->pipe, fs);
 
    return aafs;
 }
@@ -830,6 +830,7 @@ draw_install_aapoint_stage(struct draw_context *draw,
 {
    struct aapoint_stage *aapoint;
 
+   pipe->draw = (void *) draw;
 
    /*
     * Create / install AA point drawing / prim stage
@@ -850,9 +851,10 @@ draw_install_aapoint_stage(struct draw_context *draw,
    pipe->bind_fs_state = aapoint_bind_fs_state;
    pipe->delete_fs_state = aapoint_delete_fs_state;
 
-   pipe->draw = (void *) draw;
    draw->pipeline.aapoint = &aapoint->stage;
 
+   return TRUE;
+
  fail:
    if (aapoint)
       aapoint->stage.destroy( &aapoint->stage );
index 6780f275d96f0388c60cb8b484e351e9a67df9bd..21216addeab14bab783ac17dab3383b860edd0e3 100644 (file)
@@ -493,8 +493,11 @@ static void clip_destroy( struct draw_stage *stage )
 struct draw_stage *draw_clip_stage( struct draw_context *draw )
 {
    struct clipper *clipper = CALLOC_STRUCT(clipper);
+   if (clipper == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 );
+   if (!draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 ))
+      goto fail;
 
    clipper->stage.draw = draw;
    clipper->stage.point = clip_point;
@@ -507,4 +510,10 @@ struct draw_stage *draw_clip_stage( struct draw_context *draw )
    clipper->plane = draw->plane;
 
    return &clipper->stage;
+
+ fail:
+   if (clipper)
+      clipper->stage.destroy( &clipper->stage );
+
+   return NULL;
 }
index 8c13f40b554c5674233a8081fe52ec624b318c14..87aaf1f85bd0c0add4b40e00308324c7cb9cbea2 100644 (file)
@@ -120,8 +120,11 @@ static void cull_destroy( struct draw_stage *stage )
 struct draw_stage *draw_cull_stage( struct draw_context *draw )
 {
    struct cull_stage *cull = CALLOC_STRUCT(cull_stage);
+   if (cull == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &cull->stage, 0 );
+   if (!draw_alloc_temp_verts( &cull->stage, 0 ))
+      goto fail;
 
    cull->stage.draw = draw;
    cull->stage.next = NULL;
@@ -133,4 +136,10 @@ struct draw_stage *draw_cull_stage( struct draw_context *draw )
    cull->stage.destroy = cull_destroy;
 
    return &cull->stage;
+
+ fail:
+   if (cull)
+      cull->stage.destroy( &cull->stage );
+
+   return NULL;
 }
index 2aeb3095544ed4abc7d5d5998e7e15974ab1cf42..205000cbea57db259b8443b23ef9586c88ac579a 100644 (file)
@@ -224,8 +224,11 @@ static void flatshade_destroy( struct draw_stage *stage )
 struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
 {
    struct flat_stage *flatshade = CALLOC_STRUCT(flat_stage);
+   if (flatshade == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &flatshade->stage, 2 );
+   if (!draw_alloc_temp_verts( &flatshade->stage, 2 ))
+      goto fail;
 
    flatshade->stage.draw = draw;
    flatshade->stage.next = NULL;
@@ -237,6 +240,12 @@ struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
    flatshade->stage.destroy = flatshade_destroy;
 
    return &flatshade->stage;
+
+ fail:
+   if (flatshade)
+      flatshade->stage.destroy( &flatshade->stage );
+
+   return NULL;
 }
 
 
index c1dc21cd3293567f51f8eb567a5302e396b4e3a4..ffec85ccdd8aea7d64ae5bde196fa4840881d374 100644 (file)
@@ -158,6 +158,8 @@ static void offset_destroy( struct draw_stage *stage )
 struct draw_stage *draw_offset_stage( struct draw_context *draw )
 {
    struct offset_stage *offset = CALLOC_STRUCT(offset_stage);
+   if (offset == NULL)
+      goto fail;
 
    draw_alloc_temp_verts( &offset->stage, 3 );
 
@@ -171,4 +173,10 @@ struct draw_stage *draw_offset_stage( struct draw_context *draw )
    offset->stage.destroy = offset_destroy;
 
    return &offset->stage;
+
+ fail:
+   if (offset)
+      offset->stage.destroy( &offset->stage );
+
+   return NULL;
 }
index 5686729cd3d597a458c0d6f084e7e78d77d08845..ac08aa10ced11ed3291da45587565ace1856ee62 100644 (file)
@@ -686,7 +686,7 @@ pstip_set_polygon_stipple(struct pipe_context *pipe,
  * into the draw module's pipeline.  This will not be used if the
  * hardware has native support for AA lines.
  */
-void
+boolean
 draw_install_pstipple_stage(struct draw_context *draw,
                             struct pipe_context *pipe)
 {
@@ -698,7 +698,9 @@ draw_install_pstipple_stage(struct draw_context *draw,
     * Create / install AA line drawing / prim stage
     */
    pstip = draw_pstip_stage( draw );
-   assert(pstip);
+   if (pstip == NULL)
+      goto fail;
+
    draw->pipeline.pstipple = &pstip->stage;
 
    pstip->pipe = pipe;
@@ -724,4 +726,12 @@ draw_install_pstipple_stage(struct draw_context *draw,
    pipe->bind_sampler_states = pstip_bind_sampler_states;
    pipe->set_sampler_textures = pstip_set_sampler_textures;
    pipe->set_polygon_stipple = pstip_set_polygon_stipple;
+
+   return TRUE;
+
+ fail:
+   if (pstip)
+      pstip->stage.destroy( &pstip->stage );
+
+   return FALSE;
 }
index 453fd3ac7108c8c09c58ee0898a50cc26d8887f2..5910dccc43cc216eef8e5f2996487c5bd2b702a2 100644 (file)
@@ -172,8 +172,11 @@ static void twoside_destroy( struct draw_stage *stage )
 struct draw_stage *draw_twoside_stage( struct draw_context *draw )
 {
    struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage);
+   if (twoside == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &twoside->stage, 3 );
+   if (!draw_alloc_temp_verts( &twoside->stage, 3 ))
+      goto fail;
 
    twoside->stage.draw = draw;
    twoside->stage.next = NULL;
@@ -185,4 +188,10 @@ struct draw_stage *draw_twoside_stage( struct draw_context *draw )
    twoside->stage.destroy = twoside_destroy;
 
    return &twoside->stage;
+
+ fail:
+   if (twoside)
+      twoside->stage.destroy( &twoside->stage );
+
+   return NULL;
 }
index d4ddfec1b3aaef284e5ff006dc2f863254e41c51..eeb2bc43f913ded06ca5b180f2a105afcad819e6 100644 (file)
@@ -177,8 +177,11 @@ static void unfilled_destroy( struct draw_stage *stage )
 struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
 {
    struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
+   if (unfilled == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &unfilled->stage, 0 );
+   if (!draw_alloc_temp_verts( &unfilled->stage, 0 ))
+      goto fail;
 
    unfilled->stage.draw = draw;
    unfilled->stage.next = NULL;
@@ -191,4 +194,10 @@ struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
    unfilled->stage.destroy = unfilled_destroy;
 
    return &unfilled->stage;
+
+ fail:
+   if (unfilled)
+      unfilled->stage.destroy( &unfilled->stage );
+
+   return NULL;
 }
index e9821de9763769adc01ec016a96aff8a14a8434b..04438f4dd08e687777427a591dbc7843006e5ea7 100644 (file)
@@ -68,24 +68,28 @@ draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header)
  */
 boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr )
 {
-   unsigned i;
-   ubyte *store;
-
    assert(!stage->tmp);
 
    stage->tmp = NULL;
    stage->nr_tmps = nr;
-   if (nr == 0)
-      return FALSE;
 
-   store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr );
-   if (store == NULL)
-      return FALSE;
+   if (nr != 0)
+   {
+      unsigned i;
+      ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr );
+
+      if (store == NULL)
+         return FALSE;
 
-   stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );
-      
-   for (i = 0; i < nr; i++)
-      stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
+      stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );
+      if (stage->tmp == NULL) {
+         FREE(store);
+         return FALSE;
+      }
+         
+      for (i = 0; i < nr; i++)
+         stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
+   }
 
    return TRUE;
 }
index ffddc2f62c2707c6cb731718f7b0e031b042706c..a2e0812c890e8ee6ef19668cf2878f3db16ae995 100644 (file)
@@ -299,6 +299,8 @@ static void validate_destroy( struct draw_stage *stage )
 struct draw_stage *draw_validate_stage( struct draw_context *draw )
 {
    struct draw_stage *stage = CALLOC_STRUCT(draw_stage);
+   if (stage == NULL)
+      return NULL;
 
    stage->draw = draw;
    stage->next = NULL;
index c5810febe0e15bc1522b52cc74f101c853ad8bfd..afd5f5544d5ac755bea3e4fb0a33c52b0e49284a 100644 (file)
@@ -443,8 +443,7 @@ struct draw_stage *draw_vbuf_stage( struct draw_context *draw,
                                     struct vbuf_render *render )
 {
    struct vbuf_stage *vbuf = CALLOC_STRUCT(vbuf_stage);
-
-   if(!vbuf)
+   if (vbuf == NULL)
       goto fail;
    
    vbuf->stage.draw = draw;
@@ -461,7 +460,7 @@ struct draw_stage *draw_vbuf_stage( struct draw_context *draw,
    vbuf->indices = (ushort *) align_malloc( vbuf->max_indices * 
                                            sizeof(vbuf->indices[0]), 
                                            16 );
-   if(!vbuf->indices)
+   if (!vbuf->indices)
       goto fail;
    
    vbuf->vertices = NULL;
index 8101340680ec2311003f9c7206204c4951134659..ed08573382d5f115d72fe47e5176506bbe25d9ec 100644 (file)
@@ -249,8 +249,11 @@ static void widepoint_destroy( struct draw_stage *stage )
 struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
 {
    struct widepoint_stage *wide = CALLOC_STRUCT(widepoint_stage);
+   if (wide == NULL)
+      goto fail;
 
-   draw_alloc_temp_verts( &wide->stage, 4 );
+   if (!draw_alloc_temp_verts( &wide->stage, 4 ))
+      goto fail;
 
    wide->stage.draw = draw;
    wide->stage.next = NULL;
@@ -262,4 +265,10 @@ struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
    wide->stage.destroy = widepoint_destroy;
 
    return &wide->stage;
+
+ fail:
+   if (wide)
+      wide->stage.destroy( &wide->stage );
+   
+   return NULL;
 }
index 002ced21865b772d0120e0b13703b779ca4b03d9..7735173042b7465af3ce38e2a5ed8579c938e967 100644 (file)
@@ -271,6 +271,8 @@ static void fetch_emit_destroy( struct draw_pt_middle_end *middle )
 struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw )
 {
    struct fetch_emit_middle_end *fetch_emit = CALLOC_STRUCT( fetch_emit_middle_end );
+   if (fetch_emit == NULL)
+      return NULL;
  
    fetch_emit->base.prepare = fetch_emit_prepare;
    fetch_emit->base.run     = fetch_emit_run;
index 881e47d59d15cd534ed4a110c339b76b3ab2cad6..98a2cb45e4b95bd20469b5afc12ccd2f6b593377 100644 (file)
@@ -114,6 +114,8 @@ static void fetch_pipeline_run( struct draw_pt_middle_end *middle,
       (struct vertex_header *)MALLOC(fpme->vertex_size * fetch_count);
 
    if (!pipeline_verts) {
+      /* Not much we can do here - just skip the rendering.
+       */
       assert(0);
       return;
    }
index b61bb50664fe9e1ed98a0a4d4969eb565459ab67..3cc2941f960c8813b4f7acc81b3a875d3ef7ff4b 100644 (file)
@@ -487,6 +487,8 @@ static void vcache_destroy( struct draw_pt_front_end *frontend )
 struct draw_pt_front_end *draw_pt_vcache( struct draw_context *draw )
 {
    struct vcache_frontend *vcache = CALLOC_STRUCT( vcache_frontend );
+   if (vcache == NULL)
+      return NULL;
  
    vcache->base.prepare = vcache_prepare;
    vcache->base.run     = NULL;