summaryrefslogtreecommitdiffstats
path: root/core/save-xml.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-01-01 11:45:26 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-07 09:33:24 -0800
commit4d06ddd72351f7804acdaec81f0400a735581229 (patch)
treeda5faaf51b301ab3d74acad472ad34cd6a801c40 /core/save-xml.c
parentda52440963ac8920acab82502114b74c98e170a1 (diff)
downloadsubsurface-4d06ddd72351f7804acdaec81f0400a735581229.tar.gz
Dive sites: don't delete unused dive sites on save
Unused dive sites were deleted on save. This clashed with the undo system in the following scenario: 1) Delete single-use dive site. 2) Save (dive site deleted) 3) Undo (reference to freed dive site) Therefore, as a quick-fix, keep the referenced dive site around. Note that this also means that empty dive sites must not be deleted, as it might refer to a dive in the undo system. Instead only clear references to empty dive sites in the global dive table. Factor this functionality out, as it was common to the XML and git savers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/save-xml.c')
-rw-r--r--core/save-xml.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/core/save-xml.c b/core/save-xml.c
index baebb0ad9..e49e186f4 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -592,18 +592,14 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi
/* save the dive sites - to make the output consistent let's sort the table, first */
dive_site_table_sort();
+ purge_empty_dive_sites();
put_format(b, "<divesites>\n");
for (i = 0; i < dive_site_table.nr; i++) {
int j;
struct dive *d;
struct dive_site *ds = get_dive_site(i);
- if (dive_site_is_empty(ds) || !is_dive_site_used(ds, false)) {
- for_each_dive(j, d) {
- if (d->dive_site == ds)
- d->dive_site = NULL;
- }
- delete_dive_site(ds);
- i--; // since we just deleted that one
+ if (!is_dive_site_used(ds, false)) {
+ /* Only write used dive sites */
continue;
} else if (ds->name &&
(strncmp(ds->name, "Auto-created dive", 17) == 0 ||