script: Use a weak ref to remove the signal emission hook

When an object goes away we should remove the emission hook for the
state transitions, to avoid leaving hooks around.
This commit is contained in:
Emmanuele Bassi 2011-06-12 11:27:34 +01:00
parent b33973f9f8
commit d9c1a2ebbb

View File

@ -948,6 +948,8 @@ typedef struct {
ClutterState *state; ClutterState *state;
GObject *emitter; GObject *emitter;
gchar *target; gchar *target;
gulong signal_id;
gulong hook_id;
} HookData; } HookData;
typedef struct { typedef struct {
@ -985,6 +987,16 @@ clutter_script_state_change_hook (GSignalInvocationHint *ihint,
return TRUE; return TRUE;
} }
static void
clutter_script_remove_state_change_hook (gpointer user_data,
GObject *object_p)
{
HookData *hook_data = user_data;
g_signal_remove_emission_hook (hook_data->signal_id,
hook_data->hook_id);
}
static void static void
connect_each_object (gpointer key, connect_each_object (gpointer key,
gpointer value, gpointer value,
@ -1071,11 +1083,16 @@ connect_each_object (gpointer key,
hook_data->emitter = object; hook_data->emitter = object;
hook_data->state = CLUTTER_STATE (state_object); hook_data->state = CLUTTER_STATE (state_object);
hook_data->target = g_strdup (sinfo->target); hook_data->target = g_strdup (sinfo->target);
hook_data->signal_id = signal_id;
hook_data->hook_id =
g_signal_add_emission_hook (signal_id, signal_quark, g_signal_add_emission_hook (signal_id, signal_quark,
clutter_script_state_change_hook, clutter_script_state_change_hook,
hook_data, hook_data,
hook_data_free); hook_data_free);
g_object_weak_ref (hook_data->emitter,
clutter_script_remove_state_change_hook,
hook_data);
} }
signal_info_free (sinfo); signal_info_free (sinfo);