diff --git a/core/divelist.c b/core/divelist.c index e4d68b616..d55c4a182 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -773,8 +773,6 @@ void delete_single_dive(int idx) struct dive *dive = get_dive(idx); if (!dive) return; /* this should never happen */ - if (dive->selected) - deselect_dive(dive); remove_dive_from_trip(dive, divelog.trips); unregister_dive_from_dive_site(dive); delete_dive_from_table(divelog.dives, idx); @@ -973,6 +971,9 @@ void add_imported_dives(struct divelog *import_log, int flags) process_imported_dives(import_log, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &dive_sites_to_add, devices_to_add); + /* Start by deselecting all dives, so that we don't end up with an invalid selection */ + select_single_dive(NULL); + /* Add new dives to trip and site to get reference count correct. */ for (i = 0; i < dives_to_add.nr; i++) { struct dive *d = dives_to_add.dives[i];