FS#6369 - Restore a train chain if it is not possible to allocate a new orderlist

Attached to Project: OpenTTD
Opened by Juanjo (juanjo) - Sunday, 30 August 2015, 09:39 GMT
Last edited by frosch (frosch) - Friday, 30 October 2015, 16:25 GMT
Type Patch
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


In revision r27389, function CmdSellRailWagon in train_cmd.cpp.

In the lines 1378-1394, the code does these things:
1) First the command arranges the vehicle. If an error in the validation function is found, it RESTORES the train and returns an ERROR.
2) Then calculates the value of the sold vehicles.
3) Before execution of the command, it checks if a new orderlist can be created. If not, it generates an ERROR WITHOUT RESTORING the original train.

The attached patch, restores the train before generating the error. At the same time, I have also reordered the code, as for readability it seems the correct order is first checking possible errors and then calculating the cost of the command.

Anyway, it is almost impossible to reproduce the bug accidentally.

This task depends upon

Closed by  frosch (frosch)
Friday, 30 October 2015, 16:25 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r27419. Thanks for the patch!