From d3ffe2270b1541dfa3fb16a65a3ebe02ee2a8fda Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 Apr 2015 12:22:15 -0400 Subject: [PATCH] More proper cleanup work. This just leaves the tabs... --- unix/parent.c | 5 ++++- unix/window.c | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/unix/parent.c b/unix/parent.c index a01c13c6..451fdd17 100644 --- a/unix/parent.c +++ b/unix/parent.c @@ -143,11 +143,14 @@ static void parentDestroy(uiParent *pp) { uipParent *p = uipParent(pp->Internal); - p->canDestroy = TRUE; + // first, destroy the main control if (p->mainControl != NULL) { uiControlDestroy(p->mainControl); p->mainControl = NULL; } + // now we can mark the parent as ready to be destroyed + p->canDestroy = TRUE; + // finally, destroy the parent gtk_widget_destroy(GTK_WIDGET(p)); } diff --git a/unix/window.c b/unix/window.c index d87b58c2..f89541c9 100644 --- a/unix/window.c +++ b/unix/window.c @@ -10,16 +10,17 @@ struct window { int (*onClosing)(uiWindow *, void *); void *onClosingData; int margined; + gboolean canDestroy; }; static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) { struct window *w = (struct window *) data; - // return exact values just in case + // manually destroy the window ourselves; don't let the delete-event handler do it if ((*(w->onClosing))(uiWindow(w), w->onClosingData)) - return FALSE; - return TRUE; + uiWindowDestroy(uiWindow(w)); + return TRUE; // don't continue to the default delete-event handler; we destroyed the window by now } static int defaultOnClosing(uiWindow *w, void *data) @@ -31,13 +32,24 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct window *w = (struct window *) data; + if (!w->canDestroy) + // TODO switch to complain() + g_error("attempt to dispose uiWindow at %p before uiWindowDestroy()", w); uiFree(w); } +// TODO should we change the GtkWindow's child first? static void windowDestroy(uiWindow *ww) { struct window *w = (struct window *) ww; + // first, hide the window to prevent our cleanup from being noticed + gtk_widget_hide(w->widget); + // next, destroy the content uiParent + uiParentDestroy(w->content); + // now that we cleaned up properly, we can mark our window as ready to be destroyed + w->canDestroy = TRUE; + // finally, destroy the window gtk_widget_destroy(w->widget); }