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 GitHub
parent ecb761fc69
commit 42c9f84d74
26 changed files with 208 additions and 198 deletions
+2 -2
View File
@@ -129,7 +129,7 @@ RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
if (ei->climates.Test(_settings_game.game_creation.landscape) &&
(e->company_avail.Test(company) || TimerGameCalendar::date >= e->intro_date + CalendarTime::DAYS_IN_YEAR)) {
const RailVehicleInfo *rvi = &e->u.rail;
const RailVehicleInfo *rvi = &e->VehInfo<RailVehicleInfo>();
if (rvi->railveh_type != RAILVEH_WAGON) {
assert(rvi->railtypes.Any());
@@ -159,7 +159,7 @@ RailTypes GetRailTypes(bool introduces)
const EngineInfo *ei = &e->info;
if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue;
const RailVehicleInfo *rvi = &e->u.rail;
const RailVehicleInfo *rvi = &e->VehInfo<RailVehicleInfo>();
if (rvi->railveh_type != RAILVEH_WAGON) {
assert(rvi->railtypes.Any());
if (introduces) {