OpenTTD/OpenTTD

[Bug]: Train head autoreplace operations leak a unitnumber in the case where there are 1 or more wagons

Closed this issue · 1 comments

Version of OpenTTD

master (presumably since #12165)

Expected result

No unit number leaks

Actual result

Autoreplacing a train head engine with one or attached wagons leaks a unit number

Steps to reproduce

Buy a locomotive (train 1)
Buy a wagon
Add an auto-replace from the locomotive engine to something else
Press the auto-replace button in the depot window
Buy another locomotive (train 3)

If you sell all trains after performing the above steps to reproduce, then buy two more trains, does the second train have unitnumber 2 (Train 2) or 3 (Train 3)?

Edit: I was able to reproduce on b8b0181. Furthermore, the unitnumber becomes unavailable for the company until the game is saved and loaded.