From 2abdd27d020fdf5e84a1f03311da6fade1b0a28f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 13 May 2023 11:33:41 +0100 Subject: [PATCH] Fix crash when selecting conditional orders in order window --- src/order_gui.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 6e4fc73895..2d0ec2a4d2 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -2516,15 +2516,18 @@ public: VehicleOrderID sel = this->OrderGetSel(); const Order *order = this->vehicle->GetOrder(sel); - if (order != nullptr && order->IsType(OT_CONDITIONAL) && GB(order->GetXData(), 0, 16) != UINT16_MAX) { - const DispatchSchedule &ds = this->vehicle->orders->GetDispatchScheduleByIndex(GB(order->GetXData(), 0, 16)); - if (ds.ScheduleName().empty()) { - SetDParam(0, STR_TIMETABLE_ASSIGN_SCHEDULE_ID); - SetDParam(1, GB(order->GetXData(), 0, 16) + 1); - } else { - SetDParam(0, STR_JUST_RAW_STRING); - SetDParamStr(1, ds.ScheduleName().c_str()); + uint schedule_index = GB(order->GetXData(), 0, 16); + if (order != nullptr && order->IsType(OT_CONDITIONAL) && order->GetConditionVariable() == OCV_DISPATCH_SLOT && schedule_index != UINT16_MAX) { + if (schedule_index < this->vehicle->orders->GetScheduledDispatchScheduleCount()) { + const DispatchSchedule &ds = this->vehicle->orders->GetDispatchScheduleByIndex(schedule_index); + if (!ds.ScheduleName().empty()) { + SetDParam(0, STR_JUST_RAW_STRING); + SetDParamStr(1, ds.ScheduleName().c_str()); + break; + } } + SetDParam(0, STR_TIMETABLE_ASSIGN_SCHEDULE_ID); + SetDParam(1, schedule_index + 1); } else { SetDParam(0, STR_TIMETABLE_ASSIGN_SCHEDULE_NONE); }