Properly manage timeline refcounting in clutter_animation_set_timeline()

This patch fixes clutter to not crash when multiple animations share
the same timeline and the actors are explicitly destroyed before
the timeline completes (bug 672890)
This commit is contained in:
Tristan Van Berkom 2012-03-27 16:57:03 +09:00
parent ba3bfde2ea
commit 67058229f0

View File

@ -1601,7 +1601,7 @@ clutter_animation_set_timeline (ClutterAnimation *animation,
if (priv->alpha != NULL) if (priv->alpha != NULL)
cur_timeline = clutter_alpha_get_timeline (priv->alpha); cur_timeline = clutter_alpha_get_timeline (priv->alpha);
else else
cur_timeline = NULL; cur_timeline = priv->timeline;
if (cur_timeline == timeline) if (cur_timeline == timeline)
return; return;
@ -1621,10 +1621,19 @@ clutter_animation_set_timeline (ClutterAnimation *animation,
priv->timeline_completed_id = 0; priv->timeline_completed_id = 0;
priv->timeline_frame_id = 0; priv->timeline_frame_id = 0;
/* Release previously set timeline if any */
g_clear_object (&priv->timeline);
if (priv->alpha != NULL) if (priv->alpha != NULL)
clutter_alpha_set_timeline (priv->alpha, timeline); clutter_alpha_set_timeline (priv->alpha, timeline);
else else
priv->timeline = timeline; {
/* Hold a reference to the timeline if it's not reffed by the priv->alpha */
priv->timeline = timeline;
if (priv->timeline)
g_object_ref (priv->timeline);
}
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_TIMELINE]); g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_TIMELINE]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_DURATION]); g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_DURATION]);
@ -1632,8 +1641,6 @@ clutter_animation_set_timeline (ClutterAnimation *animation,
if (timeline != NULL) if (timeline != NULL)
{ {
g_object_ref (timeline);
priv->timeline_started_id = priv->timeline_started_id =
g_signal_connect (timeline, "started", g_signal_connect (timeline, "started",
G_CALLBACK (on_timeline_started), G_CALLBACK (on_timeline_started),