Fix #14945: Hang when deleting implicit orders during vehicle loading. (#14946)

This commit is contained in:
Peter Nelson
2025-12-21 15:08:13 +00:00
committed by dP
parent d5b01fb17b
commit 059f3bd685

View File

@@ -2249,22 +2249,22 @@ void Vehicle::BeginLoading()
InvalidateVehicleOrder(this, 0); InvalidateVehicleOrder(this, 0);
} else { } else {
/* Delete all implicit orders up to the station we just reached */ /* Delete all implicit orders up to the station we just reached */
VehicleOrderID cur = this->cur_implicit_order_index; const Order *order = this->GetOrder(this->cur_implicit_order_index);
auto orders = this->Orders(); while (!order->IsType(OT_IMPLICIT) || order->GetDestination() != this->last_station_visited) {
while (!orders[cur].IsType(OT_IMPLICIT) || orders[cur].GetDestination() != this->last_station_visited) { if (order->IsType(OT_IMPLICIT)) {
if (orders[cur].IsType(OT_IMPLICIT)) {
DeleteOrder(this, this->cur_implicit_order_index); DeleteOrder(this, this->cur_implicit_order_index);
/* DeleteOrder does various magic with order_indices, so resync 'order' with 'cur_implicit_order_index' */
} else { } else {
/* Skip non-implicit orders, e.g. service-orders */ /* Skip non-implicit orders, e.g. service-orders */
if (cur < this->orders->GetNext(cur)) { ++this->cur_implicit_order_index;
this->cur_implicit_order_index++; }
} else { order = this->GetOrder(this->cur_implicit_order_index);
/* Wrapped around. */ /* Wrapped around. */
if (order == nullptr) {
this->cur_implicit_order_index = 0; this->cur_implicit_order_index = 0;
order = this->GetOrder(this->cur_implicit_order_index);
} }
cur = this->orders->GetNext(cur); assert(order != nullptr);
}
} }
} }
} else if (!suppress_implicit_orders && } else if (!suppress_implicit_orders &&