From 9a6aac0459c54c322c5426bc633dc1bda3c7285e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 23 Aug 2023 23:18:59 -0400 Subject: [PATCH] path spinner demo: Don't crash --- demos/gtk-demo/path_spinner.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/demos/gtk-demo/path_spinner.c b/demos/gtk-demo/path_spinner.c index cbe9fc148e..0145223b08 100644 --- a/demos/gtk-demo/path_spinner.c +++ b/demos/gtk-demo/path_spinner.c @@ -286,6 +286,12 @@ progress_timeout (gpointer data) return G_SOURCE_CONTINUE; } +static void +unset_timeout (gpointer data) +{ + g_source_remove (GPOINTER_TO_UINT (data)); +} + GtkWidget * do_path_spinner (GtkWidget *do_widget) { @@ -295,6 +301,7 @@ do_path_spinner (GtkWidget *do_widget) { GtkWidget *picture; GdkPaintable *paintable; + guint timeout_id; window = gtk_window_new (); gtk_window_set_resizable (GTK_WINDOW (window), TRUE); @@ -308,7 +315,9 @@ do_path_spinner (GtkWidget *do_widget) g_object_unref (paintable); gtk_widget_add_tick_callback (picture, tick_cb, paintable, NULL); - g_timeout_add (100, progress_timeout, paintable); + timeout_id = g_timeout_add (100, progress_timeout, paintable); + + g_object_set_data_full (G_OBJECT (picture), "timeout", GUINT_TO_POINTER (timeout_id), unset_timeout); gtk_window_set_child (GTK_WINDOW (window), picture); }