From c10be39c03919ecc430f542bbde8adad229c5781 Mon Sep 17 00:00:00 2001 From: Gary Li Date: Sat, 11 Mar 2023 18:06:21 -0500 Subject: pathbar: do not use finalized pathbar to bind menu model to popover Nautilus fails critical assertions if the user opens then closes a new window in rapid succession in a large folder. This is because the GSource created by nautilus_path_bar_set_templates_menu to bind menu model to popover is not removed even if the pathbar has already been finalized by the user closing the window. Keep track of the source id and remove source if the pathbar is being disposed of. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2867 --- src/nautilus-pathbar.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c index 7e19e2448..83d8994c0 100644 --- a/src/nautilus-pathbar.c +++ b/src/nautilus-pathbar.c @@ -105,6 +105,7 @@ struct _NautilusPathBar NautilusFile *context_menu_file; GtkPopoverMenu *current_view_menu_popover; + guint bind_menu_model_to_popover_id; GtkWidget *current_view_menu_button; GtkWidget *button_menu_popover; GMenu *current_view_menu; @@ -241,6 +242,7 @@ bind_current_view_menu_model_to_popover (NautilusPathBar *self) { gtk_popover_menu_set_menu_model (self->current_view_menu_popover, G_MENU_MODEL (self->current_view_menu)); + self->bind_menu_model_to_popover_id = 0; return G_SOURCE_REMOVE; } @@ -342,6 +344,8 @@ nautilus_path_bar_dispose (GObject *object) { NautilusPathBar *self = NAUTILUS_PATH_BAR (object); + g_clear_handle_id (&self->bind_menu_model_to_popover_id, g_source_remove); + nautilus_path_bar_clear_buttons (self); G_OBJECT_CLASS (nautilus_path_bar_parent_class)->dispose (object); @@ -457,7 +461,10 @@ nautilus_path_bar_set_templates_menu (NautilusPathBar *self, } nautilus_gmenu_set_from_model (self->templates_submenu, menu); - g_idle_add ((GSourceFunc) bind_current_view_menu_model_to_popover, self); + if (self->bind_menu_model_to_popover_id == 0) + { + self->bind_menu_model_to_popover_id = g_idle_add ((GSourceFunc) bind_current_view_menu_model_to_popover, self); + } i = nautilus_g_menu_model_find_by_string (G_MENU_MODEL (self->current_view_menu), "nautilus-menu-item", -- cgit v1.2.1