diff options
author | António Fernandes <antoniof@gnome.org> | 2023-01-14 18:43:15 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2023-01-14 18:43:15 +0000 |
commit | 43478c4118468e45a93eb997d69f597d2bc97593 (patch) | |
tree | a30c0880da56ce328a3497c923da969130f043ca | |
parent | e13e08a9b87bd467546ef1217687c6c87f5f1f26 (diff) | |
download | nautilus-43478c4118468e45a93eb997d69f597d2bc97593.tar.gz |
view-model: Stop crashing on sort-directories-first change
Toggling sort directories first in list view causes a crash.
This is a regression in commit b9ac68eb6fb1f7aa5f815f9b15cd789758d62cba
gtk_sort_list_model_set_sorter() first unrefs the old sorter, then refs
the new sorter. The crash happens because the new sorter is the new
sorter. It gets destroyed by the unref, and therefore we crash when
trying to ref a destroyed object. (It's arguably a GTK API bug too.)
The solution (from our side) is for us to hold a temporary reference to
keep the object alive.
-rw-r--r-- | src/nautilus-view-model.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c index 2c63e62d7..4ee2c9037 100644 --- a/src/nautilus-view-model.c +++ b/src/nautilus-view-model.c @@ -357,9 +357,13 @@ nautilus_view_model_set_sorter (NautilusViewModel *self, void nautilus_view_model_sort (NautilusViewModel *self) { - /* Hack: Reset the sorter to trigger ressorting. */ - gtk_sort_list_model_set_sorter (self->sort_model, - gtk_sort_list_model_get_sorter (self->sort_model)); + g_autoptr (GtkSorter) sorter = NULL; + + /* We are not supposed to call gtk_sorter_changed() from here, so let's + * re-set the sorter to trigger re-sorting of the list. Hold a reference + * to keep the sorter from getting destroyed while re-setting. */ + sorter = g_object_ref (gtk_sort_list_model_get_sorter (self->sort_model)); + gtk_sort_list_model_set_sorter (self->sort_model, sorter); } GQueue * |