FS#5861 - Transfer + auto-refit combo causing Assertion failure

Attached to Project: OpenTTD
Opened by Simon Smith (Simons_Mith) - Sunday, 12 January 2014, 00:33 GMT
Last edited by fonsinchen (fonsinchen) - Thursday, 16 January 2014, 19:33 GMT
Type Bug
Category NewGRF
Status Closed
Assigned To fonsinchen (fonsinchen)
Operating System Mac OS X
Severity High
Priority Normal
Reported Version other
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


1.4.0-beta 2, Mac OS 10.5.8.

Hey, I think this is my first ever crash bug! A testament to the high quality of your normal work. I flagged it as high because it's an actual crash bug, albeit under quite contrived circumstances - lemme know if you have different preferences. Ta.

Reproduction is reasonably plainless. I'm presuming it's not FIRS-specific, even though FIRS is where I encountered it.

Find a coal mine. And a scrap yard. Build a road vehicle line from Scrap yard to coal mine, and transfer scrap metal using road vehicles with Transfer and Leave Empty orders. Build a train station at the coal mine. Contrive for the coal train to fill up with coal and leave before the first scrap transfer arrives.

Give the train orders to Full load with refit to available cargo.

On its first trip, that's pure coal. For the second trip, it has coal plus scrap available, but instead of refitting, it dies with an assertion failure. The saved game I'm attaching crashes for me as soon as the coal train returns to collect its second load.

I suspect it's the combination of a transfer plus an auto-refit that the problematic part. I doubt it's FIRS, coal, or scrap metal specific.
This task depends upon

Closed by  fonsinchen (fonsinchen)
Thursday, 16 January 2014, 19:33 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r26236
Comment by Alberth (Alberth) - Sunday, 12 January 2014, 09:47 GMT
It crashes with an assert failure:
~/openttd/play/src/economy.cpp:1325: void ReserveConsist(Station*, Vehicle*, CargoArray*, StationIDStack): Assertion `v->cargo_cap >= v->cargo.RemainingCount()' failed.

#7 0x00007fe3c8a6ec62 in __assert_fail () from /lib64/
#8 0x000000000077202b in ReserveConsist (st=0x1f2d280, u=0x19d5440, consist_capleft=0x0, next_station=...) at ~/openttd/play/src/economy.cpp:1325
#9 0x0000000000772b9f in LoadUnloadVehicle (front=0x19d5440) at ~/openttd/play/src/economy.cpp:1459
#10 0x0000000000773cd6 in LoadUnloadStation (st=0x1f2d280) at ~/openttd/play/src/economy.cpp:1778
#11 0x0000000000a9ef82 in CallVehicleTicks () at ~/openttd/play/src/vehicle.cpp:879
#12 0x00000000008f063b in StateGameLoop () at ~/openttd/play/src/openttd.cpp:1386
#13 0x00000000008f0985 in GameLoop () at ~/openttd/play/src/openttd.cpp:1480
#14 0x0000000000ab8840 in VideoDriver_SDL::MainLoop (this=0x177d400) at ~/openttd/play/src/video/sdl_v.cpp:776
#15 0x00000000008eecf2 in openttd_main (argc=1, argv=0x7fff8d649878) at ~/openttd/play/src/openttd.cpp:869
#16 0x000000000090426b in main (argc=1, argv=0x7fff8d649878) at ~/openttd/play/src/os/unix/unix.cpp:275

Looks like the same kind of crash as in  FS#5828 
Comment by fonsinchen (fonsinchen) - Sunday, 12 January 2014, 12:35 GMT