From ee100f59c06cbb2d91eb45ed33ecf68cf26512ee Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 24 Apr 2023 22:16:21 +0100 Subject: [PATCH] Fix #19800. Crash when more than 62 stations on a ride (#20039) * Fix #19800. Crash when more than 62 stations on a ride This is a bit of a temporary fix. The crash happens due to exhausting the space in the formatter but the format string only ever handled 4 stations so it was still not going to work for 5 <=> 62 stations. So for the time being capped the output at 4 stations. * Add changelog entry * Apply review comment --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Ride.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 13b7e982fe..a495ead473 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -28,6 +28,7 @@ - Fix: [#19733] Favorite ride of X guests integer overflow. - Fix: [#19756] Crash with title sequences containing no commands. - Fix: [#19767] No message when path is not connected to ride exit and is therefore unreachable for mechanics. +- Fix: [#19800] Crash when displaying station stats with more than 62 stations. - Fix: [#19801] The in-game load/save window cannot be resized anymore. - Fix: [#19854] Looping Coaster trains clipping through steep quarter turns down. - Fix: [#19858] Issue drawing simulate flag icon on alternate colour palettes. diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 4d9bbf2aca..9ab4efa397 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5772,7 +5772,10 @@ static void WindowRideMeasurementsPaint(WindowBase* w, DrawPixelInfo& dpi) // Ride time ft = Formatter(); int32_t numTimes = 0; - for (int32_t i = 0; i < ride->num_stations; i++) + // TODO: STR_RIDE_TIME only takes up to 4 stations modify to take more + // also if modified may need to be split into multiple format strings + // as formatter cannot take more than 256 bytes + for (int32_t i = 0; i < std::min(ride->num_stations, 4); i++) { StationIndex stationIndex = StationIndex::FromUnderlying(numTimes); auto time = ride->GetStation(stationIndex).SegmentTime; @@ -5810,7 +5813,8 @@ static void WindowRideMeasurementsPaint(WindowBase* w, DrawPixelInfo& dpi) // Ride length ft = Formatter(); int32_t numLengths = 0; - for (int32_t i = 0; i < ride->num_stations; i++) + // TODO: see above STR_RIDE_LENGTH is also only able to display max 4 + for (int32_t i = 0; i < std::min(ride->num_stations, 4); i++) { StationIndex stationIndex = StationIndex::FromUnderlying(i); auto length = ride->GetStation(stationIndex).SegmentLength;