Handle case where VehicleLengthChanged called on engine without a GRF

This commit is contained in:
Jonathan G Rennison
2023-06-28 19:03:56 +01:00
parent 3b2e917ca4
commit 5415b596b0

View File

@@ -419,6 +419,13 @@ void VehicleLengthChanged(const Vehicle *u)
{ {
/* show a warning once for each engine in whole game and once for each GRF after each game load */ /* show a warning once for each engine in whole game and once for each GRF after each game load */
const Engine *engine = u->GetEngine(); const Engine *engine = u->GetEngine();
if (engine->grf_prop.grffile == nullptr) {
// This can be reached if an engine is unexpectedly no longer attached to a GRF at all
if (GamelogGRFBugReverse(0, engine->grf_prop.local_id)) {
ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true);
}
return;
}
uint32 grfid = engine->grf_prop.grffile->grfid; uint32 grfid = engine->grf_prop.grffile->grfid;
GRFConfig *grfconfig = GetGRFConfig(grfid); GRFConfig *grfconfig = GetGRFConfig(grfid);
if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) {