From 4b21fc930649783be80bb95d7cc1fb3d618cc660 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Wed, 2 Feb 2022 14:00:52 +0100 Subject: [PATCH] try to clean up a bit better --- src/stratagus/script_player.cpp | 4 ++-- src/unit/unit.cpp | 3 +++ src/unit/unit_manager.cpp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp index 7195697c9..327a38b6c 100644 --- a/src/stratagus/script_player.cpp +++ b/src/stratagus/script_player.cpp @@ -94,8 +94,8 @@ void CPlayer::Load(lua_State *l) { const int args = lua_gettop(l); - this->Units.resize(0); - this->FreeWorkers.resize(0); + this->Units.clear(); + this->FreeWorkers.clear(); // j = 0 represent player Index. for (int j = 1; j < args; ++j) { diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index ab7c0f894..47ab04328 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -491,6 +491,9 @@ void CUnit::Release(bool final) DebugPrint("unit already free\n"); return; } + if (PlayerSlot != static_cast<size_t>(-1)) { + Player->RemoveUnit(*this); + } Assert(Orders.size() == 1); // Must be removed before here Assert(Removed); diff --git a/src/unit/unit_manager.cpp b/src/unit/unit_manager.cpp index f582db730..dc6889899 100644 --- a/src/unit/unit_manager.cpp +++ b/src/unit/unit_manager.cpp @@ -120,6 +120,7 @@ void CUnitManager::ReleaseUnit(CUnit *unit) unit->UnitManagerData.unitSlot = -1; units.pop_back(); } + Assert(unit->PlayerSlot == -1); releasedUnits.push_back(unit); unit->ReleaseCycle = GameCycle + 500; // can be reused after this time //Refs = GameCycle + (NetworkMaxLag << 1); // could be reuse after this time