From 62a9096079477436ade903cf13407a90644642eb Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 20 Oct 2021 18:50:21 +0200 Subject: [PATCH] Fix #15466: Crash when opening dropdown with 0 rows --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Dropdown.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 91838f3c8a..0bd317dde3 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -33,6 +33,7 @@ - Fix: [#15322] Circus music doesn't play. - Fix: [#15377] Entrance/exit ghost doesn't work on different stations without touching them first. - Fix: [#15451] Guest list name filter remains after group selection. +- Fix: [#15466] Crash when opening a dropdown with 0 rows. - Fix: [#15476] Crash when placing/clearing small scenery. - Fix: [#15487] Map animations do not work correctly when loading an exported SV6 file in vanilla RCT2. - Fix: [#15490] Tile inspector needlessly updates clearance height when changing surface slopes. diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index 71e9db36bc..ef6d0dc01a 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -157,7 +157,7 @@ void WindowDropdownShowTextCustomWidth( if (gDropdownNumItems == 0) { _dropdown_num_columns = 1; - _dropdown_num_rows = 0; + _dropdown_num_rows = 1; } else { @@ -231,15 +231,15 @@ void WindowDropdownShowImage( _dropdown_item_width = itemWidth; _dropdown_item_height = itemHeight; gDropdownNumItems = numItems; - // There must always be at least one column to prevent dividing by zero + // There must always be at least one column and row to prevent dividing by zero if (gDropdownNumItems == 0) { _dropdown_num_columns = 1; - _dropdown_num_rows = 0; + _dropdown_num_rows = 1; } else { - _dropdown_num_columns = numColumns; + _dropdown_num_columns = std::max(1, numColumns); _dropdown_num_rows = gDropdownNumItems / _dropdown_num_columns; if (gDropdownNumItems % _dropdown_num_columns != 0) _dropdown_num_rows++;