diff options
author | Corey Berla <corey@berla.me> | 2023-04-30 07:56:24 -0700 |
---|---|---|
committer | Corey Berla <corey@berla.me> | 2023-04-30 07:56:24 -0700 |
commit | 0b1d329f116c7455de46142071421a363de54985 (patch) | |
tree | 2d69406cc900f2ae5bf7215bd0ab53ab20b8087b | |
parent | 3136eea5bf84b7203484636efadaebd14ccb3e9d (diff) | |
download | nautilus-wip/corey/rubberband.tar.gz |
view-cell: Make view property a weak pointerwip/corey/rubberband
When the gtk list view is in the process of being destroyed, some of the
cells might still exist with an invalid reference to the nautilus view.
We are having an problem where the double click idle timeout from the
gesture click on the nautilus-view-cell times out when the view-cell
hasn't be freed but the nautilus view has. A good way to test this is
by clicking an item immediately followed by ctrl+w to close the tab
(freeing the view).
I played around with trying to get the gtk list view to free earlier
in the process (i.e. before the nautilus list base), but there were
still instances where the cell still existed by the time the nautilus
view was freed.
To be safe, make the unowned nautilus view a weak pointer of the
nautilus view cell so we can safely check for NULL values.
Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2859
-rw-r--r-- | src/nautilus-list-base.c | 6 | ||||
-rw-r--r-- | src/nautilus-view-cell.c | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c index 22440bacd..4aef5b700 100644 --- a/src/nautilus-list-base.c +++ b/src/nautilus-list-base.c @@ -432,6 +432,12 @@ on_item_click_stopped (GtkGestureClick *gesture, g_autoptr (NautilusListBase) self = nautilus_view_cell_get_view (cell); NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self); + if (self == NULL) + { + /* The view may already be gone before the cell finalized. */ + return; + } + rubberband_set_state (self, TRUE); priv->activate_on_release = FALSE; priv->deny_background_click = FALSE; diff --git a/src/nautilus-view-cell.c b/src/nautilus-view-cell.c index 6f28fd8ff..a16f36567 100644 --- a/src/nautilus-view-cell.c +++ b/src/nautilus-view-cell.c @@ -86,7 +86,7 @@ nautilus_view_cell_set_property (GObject *object, { case PROP_VIEW: { - priv->view = g_value_get_object (value); + g_set_weak_pointer (&priv->view, g_value_get_object (value)); } break; @@ -116,6 +116,7 @@ nautilus_view_cell_finalize (GObject *object) NautilusViewCellPrivate *priv = nautilus_view_cell_get_instance_private (self); g_clear_object (&priv->item); + g_clear_weak_pointer (&priv->view); G_OBJECT_CLASS (nautilus_view_cell_parent_class)->finalize (object); } |