Fix a potential crash (exposed in war1gus orc lvl 6) that could leave CPlayer->FreeWorkers in an invalid state

This commit is contained in:
Tim Felgentreff 2015-08-28 16:35:50 +02:00
parent a2ef204b23
commit 255195c499

View file

@ -812,6 +812,12 @@ void CPlayer::RemoveUnit(CUnit &unit)
void CPlayer::UpdateFreeWorkers()
{
FreeWorkers.clear();
if (FreeWorkers.capacity() != 0) {
// Just calling FreeWorkers.clear() is not always appropriate.
// Certain paths may leave FreeWorkers in an invalid state, so
// it's safer to re-initialize.
std::vector<CUnit*>().swap(FreeWorkers);
}
const int nunits = this->GetUnitCount();
for (int i = 0; i < nunits; ++i) {