Fix #14921: Crash during station autorefit if station doesn't accept current cargo type. (#14924)

Add convenience helpers to correctly retrieve goods entry cargo available/totals.

Avoids having to check if cargo data is available before accessing it, which was missing for autorefit.
This commit is contained in:
Peter Nelson
2025-12-15 18:06:43 +00:00
committed by GitHub
parent b1c0198d3f
commit ebdc82ad54
7 changed files with 37 additions and 18 deletions
+1 -1
View File
@@ -231,7 +231,7 @@ RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec,
const Station *station = Station::From(st);
/* Pick the first cargo that we have waiting */
for (const auto &[cargo, spritegroup] : roadstopspec->grf_prop.spritegroups) {
if (cargo < NUM_CARGO && station->goods[cargo].HasData() && station->goods[cargo].GetData().cargo.TotalCount() > 0) {
if (cargo < NUM_CARGO && station->goods[cargo].TotalCount() > 0) {
ctype = cargo;
this->root_spritegroup = spritegroup;
break;