diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index 0b932abdcb..4a3e3017bc 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -75,7 +75,8 @@ gtk_event_controller_set_property (GObject *object, { case PROP_WIDGET: priv->widget = g_value_get_object (value); - g_object_add_weak_pointer (G_OBJECT (priv->widget), (gpointer *) &priv->widget); + if (priv->widget) + g_object_add_weak_pointer (G_OBJECT (priv->widget), (gpointer *) &priv->widget); break; case PROP_PROPAGATION_PHASE: gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (object), diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index cbe2e363f9..c50b68476e 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -17196,8 +17196,8 @@ _gtk_widget_has_controller (GtkWidget *widget, } void -_gtk_widget_add_controller (GtkWidget *widget, - GtkEventController *controller) +_gtk_widget_add_controller (GtkWidget *widget, + GtkEventController *controller) { EventControllerData *data; GtkWidgetPrivate *priv; @@ -17249,6 +17249,8 @@ _gtk_widget_remove_controller (GtkWidget *widget, if (!data) return; + g_object_remove_weak_pointer (G_OBJECT (data->controller), (gpointer *) &data->controller); + if (g_signal_handler_is_connected (widget, data->grab_notify_id)) g_signal_handler_disconnect (widget, data->grab_notify_id);