diff --git a/commands/command_base.cpp b/commands/command_base.cpp index 26855f0e6..e264f2f1e 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -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(); +} +} diff --git a/core/divelist.c b/core/divelist.c index 09e3f372a..ed38eb4f7 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -21,6 +21,7 @@ #include "trip.h" bool autogroup = false; +extern void command_clear_from_C(); void set_autogroup(bool value) { @@ -1391,6 +1392,7 @@ void clear_dive_file_data() clear_git_id(); reset_tank_info_table(&tank_info_table); + command_clear_from_C(); /* Inform frontend of reset data. This should reset all the models. */ emit_reset_signal(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index feb385dec..5a3592607 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -64,6 +64,8 @@ function(TEST NAME FILE) subsurface_backend_shared ${TEST_SPECIFIC_LIBRARIES} subsurface_corelib + subsurface_commands + subsurface_corelib # annoying circular references RESOURCE_LIBRARY ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES} @@ -99,6 +101,8 @@ add_executable(TestQML testqml.cpp) target_link_libraries( TestQML subsurface_corelib + subsurface_commands + subsurface_corelib # annoying circular references RESOURCE_LIBRARY ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES}