From cc0a69e101e0f89c53675c350206d507f756f865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 27 Mar 2018 13:24:14 +0200 Subject: [PATCH] gl renderer: Fix some crashes When the first op is a modelview or projection change. --- gsk/gl/gskglrenderops.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c index be61a0bd3b..c7134297a4 100644 --- a/gsk/gl/gskglrenderops.c +++ b/gsk/gl/gskglrenderops.c @@ -115,17 +115,25 @@ ops_set_modelview (RenderOpBuilder *builder, { RenderOp op; graphene_matrix_t prev_mv; - RenderOp *last_op; if (builder->current_program && memcmp (&builder->program_state[builder->current_program->index].modelview, modelview, sizeof (graphene_matrix_t)) == 0) return *modelview; - last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1); - if (last_op->op == OP_CHANGE_MODELVIEW) + if (builder->render_ops->len > 0) { - last_op->modelview = *modelview; + RenderOp *last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1); + if (last_op->op == OP_CHANGE_MODELVIEW) + { + last_op->modelview = *modelview; + } + else + { + op.op = OP_CHANGE_MODELVIEW; + op.modelview = *modelview; + g_array_append_val (builder->render_ops, op); + } } else { @@ -149,12 +157,20 @@ ops_set_projection (RenderOpBuilder *builder, { RenderOp op; graphene_matrix_t prev_mv; - RenderOp *last_op; - last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1); - if (last_op->op == OP_CHANGE_PROJECTION) + if (builder->render_ops->len > 0) { - last_op->projection = *projection; + RenderOp *last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1); + if (last_op->op == OP_CHANGE_PROJECTION) + { + last_op->projection = *projection; + } + else + { + op.op = OP_CHANGE_PROJECTION; + op.projection = *projection; + g_array_append_val (builder->render_ops, op); + } } else {