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 dP
parent 914c6a3421
commit 8aade54f66
7 changed files with 37 additions and 18 deletions

View File

@@ -389,7 +389,7 @@ protected:
int diff = 0;
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
diff += (a->goods[cargo].HasData() ? a->goods[cargo].GetData().cargo.TotalCount() : 0) - (b->goods[cargo].HasData() ? b->goods[cargo].GetData().cargo.TotalCount() : 0);
diff += a->goods[cargo].TotalCount() - b->goods[cargo].TotalCount();
}
return diff < 0;
@@ -401,7 +401,7 @@ protected:
int diff = 0;
for (CargoType cargo : SetCargoBitIterator(cargo_filter)) {
diff += (a->goods[cargo].HasData() ? a->goods[cargo].GetData().cargo.AvailableCount() : 0) - (b->goods[cargo].HasData() ? b->goods[cargo].GetData().cargo.AvailableCount() : 0);
diff += a->goods[cargo].AvailableCount() - b->goods[cargo].AvailableCount();
}
return diff < 0;
@@ -561,7 +561,7 @@ public:
x -= rating_width + rating_spacing;
if (x < tr.left) break;
}
StationsWndShowStationRating(x, x + rating_width, tr.top, cargo_type, st->goods[cargo_type].HasData() ? st->goods[cargo_type].GetData().cargo.TotalCount() : 0, st->goods[cargo_type].rating);
StationsWndShowStationRating(x, x + rating_width, tr.top, cargo_type, st->goods[cargo_type].TotalCount(), st->goods[cargo_type].rating);
if (!rtl) {
x += rating_width + rating_spacing;
if (x > tr.right) break;