Fix 3ac1a2f1e4: Game crash due to invalid vehicle type information. (#14628)

Use std::variant instead of union for vehicle info.

RailVehicleInfo is now non-POD so using in a union causes undefined behaviour.
This commit is contained in:
Peter Nelson
2025-09-24 22:44:41 +01:00
committed by dP
parent 88d3faa050
commit 3bb1b847d3
27 changed files with 209 additions and 199 deletions

View File

@@ -200,7 +200,7 @@ void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteS
static void GetAircraftIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
{
const Engine *e = Engine::Get(engine);
uint8_t spritenum = e->u.air.image_index;
uint8_t spritenum = e->VehInfo<AircraftVehicleInfo>().image_index;
if (IsCustomVehicleSpriteNum(spritenum)) {
GetCustomVehicleIcon(engine, DIR_W, image_type, result);
@@ -267,7 +267,7 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoff
*/
CommandCost CmdBuildAircraft(DoCommandFlags flags, TileIndex tile, const Engine *e, Vehicle **ret)
{
const AircraftVehicleInfo *avi = &e->u.air;
const AircraftVehicleInfo *avi = &e->VehInfo<AircraftVehicleInfo>();
const Station *st = Station::GetByTile(tile);
/* Prevent building aircraft types at places which can't handle them */
@@ -438,7 +438,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v)
Money Aircraft::GetRunningCost() const
{
const Engine *e = this->GetEngine();
uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost);
uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->VehInfo<AircraftVehicleInfo>().running_cost);
return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF());
}