diff --git a/cogl/cogl-material-private.h b/cogl/cogl-material-private.h index eb20b3860..88dbfc0e8 100644 --- a/cogl/cogl-material-private.h +++ b/cogl/cogl-material-private.h @@ -138,6 +138,10 @@ struct _CoglMaterialNode /* The parent material/layer */ CoglMaterialNode *parent; + /* TRUE if the node took a strong reference on its parent. Weak + * materials for instance don't take a reference on their parent. */ + gboolean has_parent_reference; + /* As an optimization for creating leaf node materials/layers (the * most common) we don't require any list node allocations to link * to a single descendant. */ diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 905e0e5fd..720350821 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -127,6 +127,7 @@ _cogl_material_node_set_parent_real (CoglMaterialNode *node, } node->parent = parent; + node->has_parent_reference = take_strong_reference; /* Now that there is a consistent parent->child link we can remove * the parent reference if no reference was requested. If it turns @@ -160,7 +161,8 @@ _cogl_material_node_unparent_real (CoglMaterialNode *node) else parent->children = g_list_remove (parent->children, node); - cogl_object_unref (parent); + if (node->has_parent_reference) + cogl_object_unref (parent); node->parent = NULL; }