# HG changeset patch # User Olaf Wintermann # Date 1731702196 -3600 # Node ID 8be7fd628fbce4c85b53fb3fc2dacef410851a98 # Parent 03599608d55566db5d96cb384d8e85dc0284a5a7 start UiObject ref with 0 and increases ref with ui_show diff -r 03599608d555 -r 8be7fd628fbc ui/common/object.c --- a/ui/common/object.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/common/object.c Fri Nov 15 21:23:16 2024 +0100 @@ -54,7 +54,9 @@ } void ui_object_unref(UiObject *obj) { - if(--obj->ref == 0) { + // it is possible to have 0 references, in case + // a window was created but ui_show was never called + if(obj->ref == 0 || --obj->ref == 0) { if(obj->destroy) { obj->destroy(obj); } else { diff -r 03599608d555 -r 8be7fd628fbc ui/gtk/toolkit.c --- a/ui/gtk/toolkit.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/gtk/toolkit.c Fri Nov 15 21:23:16 2024 +0100 @@ -163,6 +163,7 @@ #elif GTK_MAJOR_VERSION <= 3 gtk_widget_show_all(obj->widget); #endif + obj->ref++; } void ui_close(UiObject *obj) { diff -r 03599608d555 -r 8be7fd628fbc ui/gtk/window.c --- a/ui/gtk/window.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/gtk/window.c Fri Nov 15 21:23:16 2024 +0100 @@ -80,7 +80,11 @@ uic_context_prepare_close(obj->ctx); obj->ref--; if(obj->ref > 0) { +#if GTK_CHECK_VERSION(2, 18, 0) + gtk_widget_set_visible(obj->widget, FALSE); +#else gtk_widget_hide(obj->widget); +#endif return TRUE; } else { return FALSE; @@ -100,7 +104,7 @@ static UiObject* create_window(const char *title, void *window_data, UiBool simple) { CxMempool *mp = cxBasicMempoolCreate(256); UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ref = 1; + obj->ref = 0; #ifdef UI_LIBADWAITA obj->widget = adw_application_window_new(ui_get_application());