From 460d5042691e32b232c21ff3ce4fe6bdeb22f887 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 27 Feb 2021 14:57:17 +0000 Subject: [PATCH] Fix order index wrapping when depth exceeded in AdvanceOrderIndex --- src/train_cmd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 352eacf262..92441cd9a5 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -630,6 +630,9 @@ void AdvanceOrderIndex(const Vehicle *v, VehicleOrderID &index) ++index; depth++; } while (depth < v->GetNumOrders()); + + /* Wrap around. */ + if (index >= v->GetNumOrders()) index = 0; } int PredictStationStoppingLocation(const Train *v, const Order *order, int station_length, DestinationID dest)