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
tracerestrict-sx
keldorkatarn 6 years ago committed by Jonathan G Rennison
parent 6c631c6679
commit 2f3e4044b7

@ -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);
}

Loading…
Cancel
Save