diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 070fcaf7c4..b8d32ca81b 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1129,7 +1129,7 @@ void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord) u->cur_implicit_order_index = cur; } } - if (sel_ord <= u->cur_timetable_order_index) { + if (u->cur_timetable_order_index != INVALID_VEH_ORDER_ID && sel_ord <= u->cur_timetable_order_index) { uint cur = u->cur_timetable_order_index + 1; /* Check if we don't go out of bound */ if (cur < u->GetNumOrders()) { @@ -1278,10 +1278,12 @@ void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord) } } - if (sel_ord < u->cur_timetable_order_index) { - u->cur_timetable_order_index--; - } else if (sel_ord == u->cur_timetable_order_index) { - u->cur_timetable_order_index = INVALID_VEH_ORDER_ID; + if (u->cur_timetable_order_index != INVALID_VEH_ORDER_ID) { + if (sel_ord < u->cur_timetable_order_index) { + u->cur_timetable_order_index--; + } else if (sel_ord == u->cur_timetable_order_index) { + u->cur_timetable_order_index = INVALID_VEH_ORDER_ID; + } } /* Update any possible open window of the vehicle */