From 02ce77dc08705eb6aa1260fdfb234e7af670672a Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sun, 8 Aug 2010 13:09:27 +0100 Subject: [PATCH] material: fix copying of material layer differences This fixes how we copy layer differences in _cogl_material_copy_layer_differences. We were making a redundant g_list_copy of the src differences and then iterating the src list calling _cogl_material_add_layer_difference for each entry which would double the list length, but the initial copy directly referenced the original layers which wasn't correct. Also we were initializing dest->n_layers before copying the layer differences but the act of copying the differences will re-initialize n_layers to 0 when adding the first layer_difference since it will trigger a layer_pre_change_notify and since the dest material isn't yet a STATE_LAYERS authority the state group is initialized before allowing the change. --- cogl/cogl-material.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 91d861e41..0bc515e80 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -827,9 +827,6 @@ _cogl_material_copy_differences (CoglMaterial *dest, g_list_free (dest->layer_differences); } - dest->n_layers = src->n_layers; - dest->layer_differences = g_list_copy (src->layer_differences); - for (l = src->layer_differences; l; l = l->next) { /* NB: a layer can't have more than one ->owner so we can't @@ -840,6 +837,11 @@ _cogl_material_copy_differences (CoglMaterial *dest, _cogl_material_add_layer_difference (dest, copy, FALSE); cogl_object_unref (copy); } + + /* Note: we initialize n_layers after adding the layer differences + * since the act of adding the layers will initialize n_layers to 0 + * because dest isn't initially a STATE_LAYERS authority. */ + dest->n_layers = src->n_layers; } if (differences & COGL_MATERIAL_STATE_NEEDS_BIG_STATE)