OpenTTD

Tasklist

FS#6182 - Newgrf GetVehicle cargoclass

Attached to Project: OpenTTD
Opened by Jan Skoch (The_Dude) - Thursday, 04 December 2014, 20:52 GMT
Last edited by frosch (frosch) - Sunday, 07 December 2014, 14:13 GMT
Type Bug
Category NewGRF
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

Details

Hi,
I wanted to decide whether wagon can be attached depending on its cargo class (callback 1D), but if I use it on wagon, that is not defined in newgrf (I have set only with trains), game crashes.

The reason is in newgrf_engine.cpp, static uint32 VehicleGetVariable, line about 611, variable 0x47

return (cs->classes << 16) | (cs->weight << 8) | e->GetGRF()->cargo_map[cargo_type];

It wants to access wagon's GRF, which is not defined since it is original wagon, so it returns NULL and than it wants to get some NULL property.

It pretty kills the way to get cargo class of non GRF wagon/vehicle, because there is no other variable for it.

Something like

uint8 cargotype = e->GetGRF() != NULL ? e->GetGRF()->cargo_map[cargo_type] : 0xFF;
return (cs->classes << 16) | (cs->weight << 8) | cargotype;

would be nice. I think it should not crash at least.

I can provide some savegame, crashlog and newgrf upon request.
This task depends upon

Closed by  frosch (frosch)
Sunday, 07 December 2014, 14:13 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r27075

Loading...