From fc8e68b37ae07dce6b5868ae18e02eff9b04382e Mon Sep 17 00:00:00 2001 From: George Matsumura Date: Tue, 30 Jun 2020 19:32:22 -0600 Subject: [PATCH] cogl: Fix crash when specifying only mask surface Cogl enters into an infinite recursion if a texture is specified for layer 1 of a pipeline but no texture is specified for layer 0. This works around the bug by setting the mask texture on layer 0 if there is no source texture. Signed-off-by: George Matsumura --- src/cairo-cogl-surface.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cairo-cogl-surface.c b/src/cairo-cogl-surface.c index 6e199141b..869671d3b 100644 --- a/src/cairo-cogl-surface.c +++ b/src/cairo-cogl-surface.c @@ -1746,6 +1746,7 @@ get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, { cairo_cogl_template_type template_type; CoglPipeline *pipeline; + int layer_counter = 0; switch ((int)source->type) { @@ -1783,7 +1784,10 @@ get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, &attributes); if (!texture) goto BAIL; - set_layer_texture_with_attributes (pipeline, 0, texture, &attributes); + set_layer_texture_with_attributes (pipeline, + layer_counter++, + texture, + &attributes); cogl_object_unref (texture); } @@ -1796,7 +1800,9 @@ get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, solid_pattern->color.green * solid_pattern->color.alpha, solid_pattern->color.blue * solid_pattern->color.alpha, solid_pattern->color.alpha); - cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color); + cogl_pipeline_set_layer_combine_constant (pipeline, + layer_counter++, + &color); } else { cairo_cogl_texture_attributes_t attributes; CoglTexture *texture = @@ -1806,7 +1812,10 @@ get_source_mask_operator_destination_pipeline (const cairo_pattern_t *mask, &attributes); if (!texture) goto BAIL; - set_layer_texture_with_attributes (pipeline, 1, texture, &attributes); + set_layer_texture_with_attributes (pipeline, + layer_counter++, + texture, + &attributes); cogl_object_unref (texture); } }