Fixed freeing data at stop & start. Previously the root window was set to NULL when...
[rodin/chimara.git] / libchimara / window.c
index 5cef17eee064870c5a9395e4bd4a4a738b20b9df..31b157f17077278a3b01bb357f4308acb882eade 100644 (file)
@@ -41,28 +41,39 @@ window_new_common(glui32 rock)
        return win;
 }
 
+/* Internal function: window closing stuff that is safe to call from either the
+ main thread or the Glk thread. */
+void
+trash_window_thread_independent(ChimaraGlkPrivate *glk_data, winid_t win)
+{
+       win->magic = MAGIC_FREE;
+       
+       g_list_foreach(win->history, (GFunc)g_free, NULL);
+       g_list_free(win->history);
+
+       g_string_free(win->buffer, TRUE);
+       g_hash_table_destroy(win->hyperlinks);
+       g_free(win->current_hyperlink);
+       g_free(win);
+}
+
+/* Internal function: do all the stuff necessary to close a window. Call only
+ from Glk thread. */
 static void
 window_close_common(winid_t win, gboolean destroy_node)
 {
        ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
-       
+
        if(glk_data->unregister_obj) 
        {
         (*glk_data->unregister_obj)(win, gidisp_Class_Window, win->disprock);
         win->disprock.ptr = NULL;
     }
-
+       
        if(destroy_node)
                g_node_destroy(win->window_node);
-       win->magic = MAGIC_FREE;
-
-       g_list_foreach(win->history, (GFunc)g_free, NULL);
-       g_list_free(win->history);
-
-       g_string_free(win->buffer, TRUE);
-       g_hash_table_destroy(win->hyperlinks);
-       g_free(win->current_hyperlink);
-       g_free(win);
+       
+       trash_window_thread_independent(glk_data, win);
 }
 
 /**