Skip to content

Commit

Permalink
catch exception during cleanup savepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 20, 2024
1 parent 376f0e3 commit c4a7af4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 14 additions & 7 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void AutosaveWindow::processIntern()
void AutosaveWindow::processBackground()
{
processDeleteNonPersistentSavepoint();
processCleanup();

if (!_autosaveTimepoint.has_value()) {
return;
Expand Down Expand Up @@ -119,9 +120,7 @@ void AutosaveWindow::processToolbar()
ImGui::SameLine();
ImGui::BeginDisabled(_savepointTable->isEmpty());
if (AlienImGui::ToolbarButton(ICON_FA_BROOM)) {
GenericMessageDialog::get().yesNo("Delete", "Do you really want to delete the all savepoints?", [&]() {
onClean();
});
GenericMessageDialog::get().yesNo("Delete", "Do you really want to delete the all savepoints?", [&]() { scheduleCleanup(); });
}
AlienImGui::Tooltip("Delete all save points");
ImGui::EndDisabled();
Expand All @@ -145,7 +144,7 @@ void AutosaveWindow::processTable()
if (ImGui::BeginTable("Save files", 4, flags, ImVec2(0, 0), 0.0f)) {
ImGui::TableSetupColumn("No", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(30.0f));
ImGui::TableSetupColumn("Timestamp", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(140.0f));
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(200.0f));
ImGui::TableSetupColumn("Project name", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(200.0f));
ImGui::TableSetupColumn("Time step", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed, scale(100.0f));
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow();
Expand Down Expand Up @@ -284,10 +283,13 @@ void AutosaveWindow::onCreateSavepoint()
SavepointTableService::get().insertEntryAtFront(_savepointTable.value(), entry);
}

void AutosaveWindow::onClean()
void AutosaveWindow::processCleanup()
{
auto nonPersistentEntries = SavepointTableService::get().truncate(_savepointTable.value(), 0);
scheduleDeleteNonPersistentSavepoint(nonPersistentEntries);
if (_scheduleCleanup) {
auto nonPersistentEntries = SavepointTableService::get().truncate(_savepointTable.value(), 0);
scheduleDeleteNonPersistentSavepoint(nonPersistentEntries);
_scheduleCleanup = false;
}
}

void AutosaveWindow::scheduleDeleteNonPersistentSavepoint(std::vector<SavepointEntry> const& entries)
Expand Down Expand Up @@ -319,6 +321,11 @@ void AutosaveWindow::processDeleteNonPersistentSavepoint()
_savepointsInProgressToDelete = newRequestsToDelete;
}

void AutosaveWindow::scheduleCleanup()
{
_scheduleCleanup = true;
}

void AutosaveWindow::updateSavepoint(int row)
{
auto entry = _savepointTable->at(row);
Expand Down
6 changes: 5 additions & 1 deletion source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>
void processStatusBar();

void onCreateSavepoint();
void onClean();

void scheduleDeleteNonPersistentSavepoint(std::vector<SavepointEntry> const& entries);
void processDeleteNonPersistentSavepoint();

void scheduleCleanup();
void processCleanup();

void updateSavepoint(int row);

void updateSavepointTableFromFile();
Expand Down Expand Up @@ -65,5 +67,7 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>
SavepointEntry _selectedEntry;
std::vector<SavepointEntry> _savepointsInProgressToDelete;

bool _scheduleCleanup = false;

std::optional<std::chrono::steady_clock::time_point> _autosaveTimepoint;
};

0 comments on commit c4a7af4

Please sign in to comment.