core: clearing dive data should clear undo stack

If we clear out our dive data, we also need to clear out the undo stack
because it otherwise will refer to dives that no longer exist.

The cleanest way to do that would be to do it in the same function used
to clear the dive data. Which causes us to call C++ code from C code and
really is a bit of a mess with a circular dependency between our
libraries.

But this does seem better than relying on people to remember to call
into a second function after clearing the data.

Suggested-by: Michael Andreen <michael@andreen.dev>
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-04-02 14:03:45 -07:00
parent f1c1e0ccee
commit ae12000063
3 changed files with 16 additions and 1 deletions

View file

@ -23,7 +23,10 @@ void init()
void clear()
{
undoStack->clear();
// this can get called from C code even if the Command code was never initialized
// (really only in the case of tests like TestParse)
if (undoStack)
undoStack->clear();
}
void setClean()
@ -113,3 +116,9 @@ bool placingCommand()
}
} // namespace Command
extern "C" {
void command_clear_from_C() {
Command::clear();
}
}