From 2a145d06b622b273f4ff619620581e1dc35fd6b9 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 29 Sep 2023 13:11:13 +0100 Subject: [PATCH] fixed crash on tomb unassignment (caused by incorrect params passed to formatted string) --- plugins/preserve-tombs.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/preserve-tombs.cpp b/plugins/preserve-tombs.cpp index 857597d23..245ce5949 100644 --- a/plugins/preserve-tombs.cpp +++ b/plugins/preserve-tombs.cpp @@ -70,6 +70,7 @@ static void update_tomb_assignments(color_ostream& out); void onUnitDeath(color_ostream& out, void* ptr); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { + tomb_assignments.clear(); return CR_OK; } @@ -77,6 +78,7 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector & pair){ - const auto &[unit_id, building_id] = pair; + for (auto it = tomb_assignments.begin(); it != tomb_assignments.end(); ++it){ + auto &[unit_id, building_id] = *it; const size_t tomb_idx = binsearch_index(world->buildings.other.ZONE_TOMB, building_id); if (tomb_idx == -1) { out.print("%s tomb missing: %d - removing\n", plugin_name, building_id); - return true; + it = tomb_assignments.erase(it); + continue; } const auto tomb = virtual_cast(world->buildings.other.ZONE_TOMB[tomb_idx]); if (!tomb || !tomb->flags.bits.exists) { out.print("%s tomb missing: %d - removing\n", plugin_name, building_id); - return true; + it = tomb_assignments.erase(it); + continue; } if (tomb->assigned_unit_id != unit_id) { - out.print("%s unassigned unit %d from tomb %d - removing\n", unit_id, building_id); - return true; + out.print("%s unassigned unit %d from tomb %d - removing\n", plugin_name, unit_id, building_id); + it = tomb_assignments.erase(it); + continue; } - - return false; - }); + } }