actor-meta: Disconnect on actor destroy

When destroying an Actor the various ActorMeta instance should already
be disposed - unless something is holding a reference to them, in which
case we should use the ::destroy signal to unset the ActorMeta:actor
back pointer.
This commit is contained in:
Emmanuele Bassi 2010-05-24 11:30:17 +01:00
parent f6fce05ee9
commit 7c627e1e03

View File

@ -24,6 +24,7 @@
struct _ClutterActorMetaPrivate struct _ClutterActorMetaPrivate
{ {
ClutterActor *actor; ClutterActor *actor;
guint destroy_id;
gchar *name; gchar *name;
@ -43,11 +44,29 @@ G_DEFINE_ABSTRACT_TYPE (ClutterActorMeta,
clutter_actor_meta, clutter_actor_meta,
G_TYPE_INITIALLY_UNOWNED); G_TYPE_INITIALLY_UNOWNED);
static void
on_actor_destroy (ClutterActor *actor,
ClutterActorMeta *meta)
{
meta->priv->actor = NULL;
}
static void static void
clutter_actor_meta_real_set_actor (ClutterActorMeta *meta, clutter_actor_meta_real_set_actor (ClutterActorMeta *meta,
ClutterActor *actor) ClutterActor *actor)
{ {
if (meta->priv->actor == actor)
return;
if (meta->priv->destroy_id != 0)
g_signal_handler_disconnect (meta->priv->actor, meta->priv->destroy_id);
meta->priv->actor = actor; meta->priv->actor = actor;
if (meta->priv->actor != NULL)
meta->priv->destroy_id = g_signal_connect (meta->priv->actor, "destroy",
G_CALLBACK (on_actor_destroy),
meta);
} }
static void static void
@ -107,6 +126,9 @@ clutter_actor_meta_finalize (GObject *gobject)
{ {
ClutterActorMetaPrivate *priv = CLUTTER_ACTOR_META (gobject)->priv; ClutterActorMetaPrivate *priv = CLUTTER_ACTOR_META (gobject)->priv;
if (priv->destroy_id != 0 && priv->actor != NULL)
g_signal_handler_disconnect (priv->actor, priv->destroy_id);
g_free (priv->name); g_free (priv->name);
G_OBJECT_CLASS (clutter_actor_meta_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_actor_meta_parent_class)->finalize (gobject);