Use lower_bound instead of equal_range in StationCargoList::ShiftCargo

Calling erase could potentially invalidate the upper_bound iterator
pull/174/head
Jonathan G Rennison 4 years ago
parent ea8a89e377
commit 1c768705a1

@ -906,8 +906,7 @@ void StationCargoList::Append(CargoPacket *cp, StationID next)
template <class Taction>
bool StationCargoList::ShiftCargo(Taction &action, StationID next)
{
std::pair<Iterator, Iterator> range(this->packets.equal_range(next));
for (Iterator it(range.first); it != range.second && it.GetKey() == next;) {
for (Iterator it = this->packets.lower_bound(next); it != this->packets.end() && it.GetKey() == next;) {
if (action.MaxMove() == 0) return false;
CargoPacket *cp = *it;
if (action(cp)) {

Loading…
Cancel
Save