From a94ea93bde8382691b8eea1f047b20c0c689c51f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 18 Nov 2010 10:53:01 +0000 Subject: [PATCH] paint-volume: Do not take a reference on the actor The paint volume structure is cached in the Actor it references, and this causes a reference cycle. The paint volume is going to be used when painting, so the actor must still be valid - otherwise Clutter will bail out far before than accessing the actor pointer in ClutterPaintVolume. Otherwise, we could have used dispose() to check for a valid actor and remove a reference if the actor field is !NULL; it feels less clean, though, since we're effectively managing an extra reference on ourselves. http://bugzilla.clutter-project.org/show_bug.cgi?id=2431 --- clutter/clutter-actor.c | 8 +++----- clutter/clutter-paint-volume.c | 18 +++--------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 667947e31..5f5d30f8a 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -2694,7 +2694,6 @@ clutter_actor_set_rotation_internal (ClutterActor *self, { ClutterActorPrivate *priv = self->priv; - g_object_ref (self); g_object_freeze_notify (G_OBJECT (self)); switch (axis) @@ -2716,7 +2715,6 @@ clutter_actor_set_rotation_internal (ClutterActor *self, } g_object_thaw_notify (G_OBJECT (self)); - g_object_unref (self); clutter_actor_queue_redraw (self); } @@ -11692,7 +11690,7 @@ clutter_actor_get_transformed_paint_volume (ClutterActor *self, return NULL; volume = clutter_actor_get_paint_volume (self); - if (!volume) + if (volume == NULL) return NULL; _clutter_actor_get_relative_modelview (self, relative_to_ancestor, &matrix); @@ -11702,8 +11700,8 @@ clutter_actor_get_transformed_paint_volume (ClutterActor *self, _clutter_paint_volume_copy_static (volume, transformed_volume); _clutter_paint_volume_transform (transformed_volume, &matrix); _clutter_paint_volume_axis_align (transformed_volume); - g_object_unref (transformed_volume->actor); - transformed_volume->actor = g_object_ref (relative_to_ancestor); + _clutter_paint_volume_set_reference_actor (transformed_volume, + relative_to_ancestor); return transformed_volume; } diff --git a/clutter/clutter-paint-volume.c b/clutter/clutter-paint-volume.c index 4b6e98900..2eb1327b1 100644 --- a/clutter/clutter-paint-volume.c +++ b/clutter/clutter-paint-volume.c @@ -60,7 +60,7 @@ _clutter_paint_volume_new (ClutterActor *actor) pv = g_slice_new (ClutterPaintVolume); - pv->actor = g_object_ref (actor); + pv->actor = actor; memset (pv->vertices, 0, 8 * sizeof (ClutterVertex)); @@ -95,7 +95,7 @@ _clutter_paint_volume_init_static (ClutterActor *actor, { g_return_if_fail (actor != NULL); - pv->actor = g_object_ref (actor); + pv->actor = actor; memset (pv->vertices, 0, 8 * sizeof (ClutterVertex)); @@ -114,7 +114,6 @@ _clutter_paint_volume_copy_static (const ClutterPaintVolume *src_pv, g_return_if_fail (src_pv != NULL && dst_pv != NULL); memcpy (dst_pv, src_pv, sizeof (ClutterPaintVolume)); - g_object_ref (dst_pv->actor); dst_pv->is_static = TRUE; } @@ -136,9 +135,6 @@ clutter_paint_volume_copy (const ClutterPaintVolume *pv) g_return_val_if_fail (pv != NULL, NULL); copy = g_slice_dup (ClutterPaintVolume, pv); - if (copy->actor) - g_object_ref (copy->actor); - copy->is_static = FALSE; return copy; @@ -148,11 +144,6 @@ void _clutter_paint_volume_set_from_volume (ClutterPaintVolume *pv, const ClutterPaintVolume *src) { - if (src->actor != pv->actor) - { - g_object_unref (pv->actor); - g_object_ref (src->actor); - } memcpy (pv, src, sizeof (ClutterPaintVolume)); } @@ -169,8 +160,6 @@ clutter_paint_volume_free (ClutterPaintVolume *pv) { g_return_if_fail (pv != NULL); - g_object_unref (pv->actor); - if (G_LIKELY (pv->is_static)) return; @@ -918,6 +907,5 @@ _clutter_paint_volume_set_reference_actor (ClutterPaintVolume *pv, { g_return_if_fail (pv != NULL); - g_object_unref (pv->actor); - pv->actor = g_object_ref (actor); + pv->actor = actor; }