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.
This commit is contained in:
2026-02-16 15:37:59 -07:00
parent 287afb4b1d
commit a6af143ba7

View File

@@ -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;
}