From a6af143ba7bed6ff0911d15753864fac099309ce Mon Sep 17 00:00:00 2001 From: deepend Date: Mon, 16 Feb 2026 15:37:59 -0700 Subject: [PATCH] Fixed the Windows GTK3 native file chooser lifetime handling by adding an idle callback (gtkutil_native_dialog_unref_idle) that performs g_object_unref(native) outside the button-release signal stack. This avoids the crash path when cancelling the Load file dialog. Updated the native chooser code path to replace immediate unref with deferred unref via g_idle_add(...) after gtk_native_dialog_run, while preserving the existing accept-only file handling behavior. --- src/fe-gtk/gtkutil.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c index a1859674..5f332353 100644 --- a/src/fe-gtk/gtkutil.c +++ b/src/fe-gtk/gtkutil.c @@ -492,6 +492,15 @@ gtkutil_file_req_response (GtkWidget *dialog, gint res, struct file_req *freq) } } +#if defined (WIN32) && HAVE_GTK3 +static gboolean +gtkutil_native_dialog_unref_idle (gpointer native) +{ + g_object_unref (native); + return G_SOURCE_REMOVE; +} +#endif + void gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *userdata, char *filter, char *extensions, int flags) @@ -582,7 +591,11 @@ gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *us if (response == GTK_RESPONSE_ACCEPT) gtkutil_file_req_done_chooser (native_chooser, freq); - g_object_unref (native); + /* + * Defer unref until idle to avoid disposing the native chooser while + * still in the button-release signal stack on Windows. + */ + g_idle_add (gtkutil_native_dialog_unref_idle, native); g_free (freq); return; }