From bc513532c1e91ee65439d96cdd7408efb28b4801 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 26 Feb 2016 10:43:07 -0500 Subject: [PATCH] gui/idle: Add a function to disable processing idle tasks This is needed during ocarina shutdown to prevent a segfault. Signed-off-by: Anna Schumaker --- gui/idle.c | 12 +++++++++++- gui/ocarina.c | 3 +-- include/gui/idle.h | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gui/idle.c b/gui/idle.c index 79dc6208..31e962b0 100644 --- a/gui/idle.c +++ b/gui/idle.c @@ -5,6 +5,8 @@ #include #include +static guint idle_id = 0; + static gboolean __on_idle(gpointer data) { GtkProgressBar *progress = GTK_PROGRESS_BAR(data); @@ -14,6 +16,7 @@ static gboolean __on_idle(gpointer data) return gtk_widget_is_visible(gui_builder_widget("o_window")); } else { gtk_widget_hide(GTK_WIDGET(progress)); + idle_id = 0; return G_SOURCE_REMOVE; } } @@ -23,5 +26,12 @@ void gui_idle_enable() GtkWidget *progress = gui_builder_widget("o_idle_progress"); gtk_widget_show(progress); - g_idle_add(__on_idle, progress); + idle_id = g_idle_add(__on_idle, progress); +} + +void gui_idle_disable() +{ + if (idle_id) + g_source_remove(idle_id); + idle_cancel(); } diff --git a/gui/ocarina.c b/gui/ocarina.c index c9e0ff9d..bfb37f28 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -2,7 +2,6 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -75,7 +74,7 @@ static void __ocarina_startup(GApplication *application, gpointer data) static void __ocarina_shutdown(GApplication *application, gpointer data) { - idle_cancel(); + gui_idle_disable(); core_deinit(); gui_window_deinit(); diff --git a/include/gui/idle.h b/include/gui/idle.h index 0101751a..e579c268 100644 --- a/include/gui/idle.h +++ b/include/gui/idle.h @@ -7,4 +7,7 @@ /* Called to enable processing idle queue tasks. */ void gui_idle_enable(); +/* Called to disable processing idle queue tasks. */ +void gui_idle_disable(); + #endif /* OCARINA_GUI_IDLE_H */