draw: propogate lots of errors

This commit is contained in:
Keith Whitwell 2008-04-21 17:03:37 +01:00
parent 0cd90a917d
commit 0d4ece4c5a
17 changed files with 120 additions and 35 deletions

View 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);

View 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;
}

View 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 );

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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 );
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);
if (store == NULL)
return FALSE;
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;
}

View 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;

View 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;

View 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;
}

View 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;

View 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;
}

View 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;