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.
This commit is contained in:
Robert Bragg 2010-08-08 13:09:27 +01:00
parent a75a7fadab
commit 02ce77dc08

View File

@ -827,9 +827,6 @@ _cogl_material_copy_differences (CoglMaterial *dest,
g_list_free (dest->layer_differences); 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) for (l = src->layer_differences; l; l = l->next)
{ {
/* NB: a layer can't have more than one ->owner so we can't /* 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_material_add_layer_difference (dest, copy, FALSE);
cogl_object_unref (copy); 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) if (differences & COGL_MATERIAL_STATE_NEEDS_BIG_STATE)