From: Brian Paul Date: Fri, 9 Sep 2011 19:59:20 +0000 (-0600) Subject: llvmpipe: add some null pointer checks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=023ca40d80670ac0eee8c755ca5f54b1e7c2712e;p=mesa.git llvmpipe: add some null pointer checks It's not clear if these are acceptable cases so issue a one-time warning in debug builds when we hit them. Fixes segfault in piglit fbo-mipmap-copypix test. Reviewed-by: José Fonseca --- diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index dafadc1ea9b..2bb61fcc7c4 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -339,6 +339,15 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task, const unsigned tile_x = task->x, tile_y = task->y; unsigned x, y; + if (!variant) { + static boolean warned = FALSE; + if (!warned) { + debug_warning("null variant pointer"); + warned = TRUE; + } + return; + } + if (inputs->disable) { /* This command was partially binned and has been disabled */ return; @@ -391,6 +400,19 @@ lp_rast_shade_tile_opaque(struct lp_rasterizer_task *task, const struct lp_scene *scene = task->scene; unsigned i; + if (!task->state) { + /* This indicates that some sort of rendering command was queued + * before we set up the rasterization state. Just returning here + * allows the piglit fbo-mipmap-copypix test to run/pass. + */ + static boolean warned = FALSE; + if (!warned) { + debug_warning("null state pointer"); + warned = TRUE; + } + return; + } + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); /* this will prevent converting the layout from tiled to linear */ @@ -785,6 +807,10 @@ static PIPE_THREAD_ROUTINE( thread_func, init_data ) boolean debug = false; while (1) { + /* make sure these pointers aren't pointing to old data */ + task->scene = NULL; + task->state = NULL; + /* wait for work */ if (debug) debug_printf("thread %d waiting for work\n", task->thread_index); diff --git a/src/gallium/drivers/llvmpipe/lp_rast_debug.c b/src/gallium/drivers/llvmpipe/lp_rast_debug.c index 03e67dc8177..b7568ec99c0 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast_debug.c +++ b/src/gallium/drivers/llvmpipe/lp_rast_debug.c @@ -62,6 +62,9 @@ get_variant( const struct lp_rast_state *state, const struct cmd_block *block, int k ) { + if (!state) + return NULL; + if (block->cmd[k] == LP_RAST_OP_SHADE_TILE || block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE || block->cmd[k] == LP_RAST_OP_TRIANGLE_1 || @@ -140,9 +143,14 @@ debug_shade_tile(int x, int y, char val) { const struct lp_rast_shader_inputs *inputs = arg.shade_tile; - boolean blend = tile->state->variant->key.blend.rt[0].blend_enable; + boolean blend; unsigned i,j; + if (!tile->state) + return 0; + + blend = tile->state->variant->key.blend.rt[0].blend_enable; + if (inputs->disable) return 0;