From df738d0a8c601a9d8afde7273717ebd926d90eda Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Apr 2009 12:39:35 +0100 Subject: [PATCH] [animation] Do not unref on ::complete by default Bug 1535 - Complete animation always unrefs ClutterAnimation (even after g_object_ref_sink) Animations created through clutter_animation_new() should not automagically unref themselves by default on ::complete. We only want that behaviour for Animations created by the clutter_actor_animate* family of functions, since those provide the automagic memory management. --- clutter/clutter-animation.c | 51 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/clutter/clutter-animation.c b/clutter/clutter-animation.c index 4bad4ea29..73d5ae1ec 100644 --- a/clutter/clutter-animation.c +++ b/clutter/clutter-animation.c @@ -109,6 +109,7 @@ clutter_animation_finalize (GObject *gobject) { ClutterAnimationPrivate *priv = CLUTTER_ANIMATION (gobject)->priv; + CLUTTER_NOTE (ANIMATION, "Destroying properties hash table"); g_hash_table_destroy (priv->properties); G_OBJECT_CLASS (clutter_animation_parent_class)->finalize (gobject); @@ -237,19 +238,6 @@ clutter_animation_get_property (GObject *gobject, } } -static void -clutter_animation_real_completed (ClutterAnimation *animation) -{ - CLUTTER_NOTE (ANIMATION, "Animation [%p] complete: unreffing", - animation); - - /* the signal emission takes a reference on the animation, which - * means that even if we unref it here, it'll be valid for the - * whole duration of the emission chain - */ - g_object_unref (animation); -} - static void clutter_animation_class_init (ClutterAnimationClass *klass) { @@ -261,8 +249,6 @@ clutter_animation_class_init (ClutterAnimationClass *klass) g_type_class_add_private (klass, sizeof (ClutterAnimationPrivate)); - klass->completed = clutter_animation_real_completed; - gobject_class->set_property = clutter_animation_set_property; gobject_class->get_property = clutter_animation_get_property; gobject_class->dispose = clutter_animation_dispose; @@ -1232,9 +1218,14 @@ clutter_animation_get_alpha (ClutterAnimation *animation) * clutter_animation_completed: * @animation: a #ClutterAnimation * - * Emits the ::completed signal on @animation. After this function - * terminates @animation will be unreferenced and it will not be - * valid anymore, unless g_object_ref() was called before + * Emits the ::completed signal on @animation + * + * When using this function with a #ClutterAnimation created + * by the clutter_actor_animate() family of functions, @animation + * will be unreferenced and it will not be valid anymore, + * unless g_object_ref() was called before calling this function + * or unless a reference was taken inside a handler for the + * #ClutterAnimation::completed signal * * Since: 1.0 */ @@ -1246,6 +1237,15 @@ clutter_animation_completed (ClutterAnimation *animation) g_signal_emit (animation, animation_signals[COMPLETED], 0); } +static void +on_animation_completed (ClutterAnimation *animation) +{ + CLUTTER_NOTE (ANIMATION, "Animation[%p] completed, unreferencing", + animation); + + g_object_unref (animation); +} + /* * starts the timeline */ @@ -1401,6 +1401,10 @@ clutter_animation_setupv (ClutterAnimation *animation, &values[i], pspec); } + + g_signal_connect (animation, "completed", + G_CALLBACK (on_animation_completed), + NULL); } static void @@ -1459,6 +1463,10 @@ clutter_animation_setup_valist (ClutterAnimation *animation, property_name = va_arg (var_args, gchar*); } + + g_signal_connect (animation, "completed", + G_CALLBACK (on_animation_completed), + NULL); } /** @@ -1637,9 +1645,9 @@ clutter_actor_animate_with_timeline (ClutterActor *actor, * to control the animation or to know when the animation has been * completed. * - * If a name argument starts with "signal::" the two following arguments are - * used as callback function and userdata for a signal handler installed on the - * #ClutterAnimation object, for instance: + * If a name argument starts with "signal::" the two following arguments + * are used as callback function and userdata for a signal handler installed + * on the #ClutterAnimation object, for instance: * * |[ * @@ -1656,7 +1664,6 @@ clutter_actor_animate_with_timeline (ClutterActor *actor, * NULL); * ]| * - * * Calling this function on an actor that is already being animated * will cause the current animation to change with the new final values, * the new easing mode and the new duration - that is, this code: