From 2cbd76593a8d15482683c66d38341759f93725c4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 21 Aug 2023 11:42:33 +0100 Subject: [PATCH] Fix #11215: Assert in NewGRF parameters window (manual parameter mode) (#11217) --- src/newgrf_gui.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index f6aa841972..375cc0572d 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -352,10 +352,9 @@ struct NewGRFParametersWindow : public Window { case WID_NP_BACKGROUND: { if (!this->editable) break; - auto it = this->vscroll->GetScrolledItemFromWidget(this->grf_config->param_info, pt.y, this, WID_NP_BACKGROUND); - if (it == this->grf_config->param_info.end()) break; + uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND); + if (num >= this->vscroll->GetCount()) break; - uint num = it - this->grf_config->param_info.begin(); if (this->clicked_row != num) { this->CloseChildWindows(WC_QUERY_STRING); this->CloseChildWindows(WC_DROPDOWN_MENU); @@ -367,7 +366,7 @@ struct NewGRFParametersWindow : public Window { int x = pt.x - r.left; if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x; - GRFParameterInfo &par_info = it->has_value() ? it->value() : GetDummyParameterInfo(num); + GRFParameterInfo &par_info = this->GetParameterInfo(num); /* One of the arrows is clicked */ uint32_t old_val = par_info.GetValue(this->grf_config);