From 77514d6960f563e1cb79f8510e123ee49461d24d Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Tue, 6 Nov 2018 23:30:55 +0100 Subject: [PATCH] direct: Fix crash when dismissing modifications Fixes obscure crash on g_menu_model_get_n_items seen in various downstream crash collectors, e.g. https://retrace.fedoraproject.org/faf/reports/2020125/ https://bugs.launchpad.net/ubuntu/+source/shotwell/+bug/1723973 --- src/Photo.vala | 16 ++++++---------- src/direct/DirectPhotoPage.vala | 8 ++++---- 2 files changed, 10 insertions(+), 14 deletions(-) Index: shotwell-0.30.1/src/Photo.vala =================================================================== --- shotwell-0.30.1.orig/src/Photo.vala +++ shotwell-0.30.1/src/Photo.vala @@ -429,7 +429,7 @@ public abstract class Photo : PhotoSourc // need to remove all transformations as they're keyed to the editable's // coordinate system - internal_remove_all_transformations(false); + remove_all_transformations(false); } } @@ -1519,7 +1519,7 @@ public abstract class Photo : PhotoSourc row.master = original_master; row.master.copy_from(reimport_state.row.master); if (!reimport_state.metadata_only) - internal_remove_all_transformations(false); + remove_all_transformations(false); } if (reimport_state.metadata != null) @@ -1596,7 +1596,7 @@ public abstract class Photo : PhotoSourc lock (row) { editable = reimport_state.backing_state; set_orientation(reimport_state.backing_state.original_orientation); - internal_remove_all_transformations(false); + remove_all_transformations(false); } } else { set_orientation(reimport_state.backing_state.original_orientation); @@ -2820,11 +2820,7 @@ public abstract class Photo : PhotoSourc return committed; } - public void remove_all_transformations() { - internal_remove_all_transformations(true); - } - - private void internal_remove_all_transformations(bool notify) { + public void remove_all_transformations(bool notify = true) { bool is_altered = false; lock (row) { is_altered = PhotoTable.get_instance().remove_all_transformations(row.photo_id); @@ -3907,7 +3903,7 @@ public abstract class Photo : PhotoSourc // transformations are in the master's coordinate system, not the editable's ... don't // notify photo is altered *yet* because update_editable will notify, and want to avoid // stacking them up - internal_remove_all_transformations(false); + remove_all_transformations(false); update_editable(false, file_format.create_reader(file.get_path())); } @@ -4077,7 +4073,7 @@ public abstract class Photo : PhotoSourc } if (remove_transformations) - internal_remove_all_transformations(false); + remove_all_transformations(false); if (has_editable) { notify_baseline_replaced(); Index: shotwell-0.30.1/src/direct/DirectPhotoPage.vala =================================================================== --- shotwell-0.30.1.orig/src/direct/DirectPhotoPage.vala +++ shotwell-0.30.1/src/direct/DirectPhotoPage.vala @@ -295,7 +295,7 @@ public class DirectPhotoPage : EditingHo base.update_actions(selected_count, count); } - private bool check_ok_to_close_photo(Photo? photo) { + private bool check_ok_to_close_photo(Photo? photo, bool notify = true) { // Means we failed to load the photo for some reason. Do not block // shutdown if (photo == null) @@ -307,7 +307,7 @@ public class DirectPhotoPage : EditingHo if (drop_if_dirty) { // need to remove transformations, or else they stick around in memory (reappearing // if the user opens the file again) - photo.remove_all_transformations(); + photo.remove_all_transformations(notify); return true; } @@ -320,7 +320,7 @@ public class DirectPhotoPage : EditingHo _("Close _without Saving")); if (response == Gtk.ResponseType.YES) - photo.remove_all_transformations(); + photo.remove_all_transformations(notify); else if (response == Gtk.ResponseType.NO) { if (is_writeable) save(photo.get_file(), 0, ScaleConstraint.ORIGINAL, Jpeg.Quality.HIGH, @@ -336,7 +336,7 @@ public class DirectPhotoPage : EditingHo } public bool check_quit() { - return check_ok_to_close_photo(get_photo()); + return check_ok_to_close_photo(get_photo(), false); } protected override bool confirm_replace_photo(Photo? old_photo, Photo new_photo) {