diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-19 14:44:27 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 403dd5a8918d4acab33cdd0a400570003244ca5e (patch) | |
tree | e3811fdcf42dc22980702c5f6594a09921a461d3 /core/divelist.h | |
parent | 8074f12b91f7397a66c7994aabd0c3dde68b1253 (diff) | |
download | subsurface-403dd5a8918d4acab33cdd0a400570003244ca5e.tar.gz |
Undo: fix multi-level undo of delete-dive and remove-dive-from-trip
The original undo-code was fundamentally broken. Not only did it leak
resources (copied trips were never freed), it also kept references
to trips or dives that could be changed by other commands. Thus,
anything more than a single undo could lead to crashes.
Two ways of fixing this were considered
1) Don't store pointers, but unique dive-ids and trip-ids.
Whereas such unique ids exist for dives, they would have to be
implemented for trips.
2) Don't free objects in the backend.
Instead, take ownership of deleted objects in the undo-object.
Thus, all references in previous undo-objects are guaranteed to
still exist (unless the objects are deleted elsewhere).
After some contemplation, the second method was chosen, because
it is significantly less intrusive. While touching the undo-objects,
clearly separate backend from ui-code, such that they can ultimately
be reused for mobile.
Note that if other parts of the code delete dives, crashes can still
be provoked. Notable examples are split/merge dives. These will have
to be fixed later. Nevertheless, the new code is a significant
improvement over the old state.
While touching the code, implement proper translation string based
on Qt's plural-feature (using %n).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divelist.h')
-rw-r--r-- | core/divelist.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/divelist.h b/core/divelist.h index ac9435356..3687b0881 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -26,6 +26,7 @@ struct dive **grow_dive_table(struct dive_table *table); extern void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p); extern int get_divenr(const struct dive *dive); extern int get_divesite_idx(const struct dive_site *ds); +extern struct dive_trip *unregister_dive_from_trip(struct dive *dive, short was_autogen); extern void remove_dive_from_trip(struct dive *dive, short was_autogen); extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive); extern void autogroup_dives(void); |