Fix crash in NewGRF parameters window (manual parameter mode)

See: https://github.com/OpenTTD/OpenTTD/issues/11215
This commit is contained in:
Jonathan G Rennison
2023-08-20 11:27:42 +01:00
parent 19835b51ee
commit ff61b6d243

View File

@@ -365,10 +365,9 @@ struct NewGRFParametersWindow : public Window {
case WID_NP_BACKGROUND: { case WID_NP_BACKGROUND: {
if (!this->editable) break; if (!this->editable) break;
auto it = this->vscroll->GetScrolledItemFromWidget(this->grf_config->param_info, pt.y, this, WID_NP_BACKGROUND); uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND);
if (it == this->grf_config->param_info.end()) break; if (num >= this->vscroll->GetCount()) break;
uint num = it - this->grf_config->param_info.begin();
if (this->clicked_row != num) { if (this->clicked_row != num) {
DeleteChildWindows(WC_QUERY_STRING); DeleteChildWindows(WC_QUERY_STRING);
HideDropDownMenu(this); HideDropDownMenu(this);
@@ -380,7 +379,7 @@ struct NewGRFParametersWindow : public Window {
int x = pt.x - r.left; int x = pt.x - r.left;
if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x; 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 */ /* One of the arrows is clicked */
uint32 old_val = par_info.GetValue(this->grf_config); uint32 old_val = par_info.GetValue(this->grf_config);