FIX: TraceRestrictSlots: Fix crash when removing vehicle from slot. Invalid iterator got used. (it was no longer valid after calling erase with it)

(cherry picked from commit 3571f1bc898b9ffd8b124040882caa5357085f42)

Fixes: #37
This commit is contained in:
keldorkatarn 2018-04-11 21:25:15 +02:00 committed by Jonathan G Rennison
parent 6c631c6679
commit 2f3e4044b7

View File

@ -1462,8 +1462,11 @@ void TraceRestrictSlot::DeIndex(VehicleID id)
auto range = slot_vehicle_index.equal_range(id);
for (auto it = range.first; it != range.second; ++it) {
if (it->second == this->index) {
bool is_first_in_range = (it == range.first);
auto next = slot_vehicle_index.erase(it);
if (it == range.first && next == range.second) {
if (is_first_in_range && next == range.second) {
/* Only one item, which we've just erased, clear the vehicle flag */
ClrBit(Train::Get(id)->flags, VRF_HAVE_SLOT);
}