Fix #9545: Crash when all cargo types are disabled. (#11432)

This is not a very useful state, but it's nice to not crash.

Some parts of the game don't (yet) check for cargo types being redefined, that is out-of-scope here.

(cherry picked from commit bbd64bbe2b)
This commit is contained in:
Peter Nelson
2023-11-04 14:42:47 +00:00
committed by Jonathan G Rennison
parent 0b226865d5
commit 480e03360b
2 changed files with 5 additions and 3 deletions

View File

@@ -378,7 +378,6 @@ protected:
if (this->num_on_x_axis == 0) return;
assert(this->num_on_x_axis > 0);
assert(this->num_dataset > 0);
/* draw text strings on the y axis */
int64 y_label = interval.highest;
@@ -1274,6 +1273,8 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
return;
}
size->height = FONT_HEIGHT_SMALL + WidgetDimensions::scaled.framerect.Vertical();
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
SetDParam(0, cs->name);
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
@@ -1469,7 +1470,7 @@ static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_CPR_MATRIX), SetFill(1, 0), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_CPR_MATRIX_SCROLLBAR),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),