From 65cdb3589841aa597ead288c7123979bc095418a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 9 Oct 2020 00:39:42 +0100 Subject: [PATCH] TBTR: Fix CmdDeleteVirtualTrain deleting non-head vehicles Deleting a non-head virtual vehicle left a dangling next pointer on the previous vehicle. Delete the head instead. Check for non-virtual vehicles --- src/vehicle_cmd.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index ed44eb7429..6c5481c4a7 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -1109,7 +1109,12 @@ CommandCost CmdDeleteVirtualTrain(TileIndex tile, DoCommandFlag flags, uint32 p1 return CMD_ERROR; } + vehicle = vehicle->First(); + Train* train = Train::From(vehicle); + if (!train->IsVirtual()) { + return CMD_ERROR; + } bool should_execute = (flags & DC_EXEC) != 0;