From aa519879a76e82d870bb1353eee7dfdf8ea07764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 15 Jun 2025 23:05:55 +0200 Subject: [PATCH 1/2] Fix #24617: Prevent hired boat with 0 speed causing division by 0 --- distribution/changelog.txt | 1 + src/openrct2/ride/Vehicle.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 33292ea8b6..3c3b99be94 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -16,6 +16,7 @@ - Fix: [#24576] It is possible to edit open rides in certain circumstances. - Fix: [#24589] Music tab doesn’t fully render in multiplayer. - Fix: [#24615] Blank strings in Windows installer. +- Fix: [#24617] ‘Divide by zero’ error when updating boat hire acceleration. 0.4.23 (2025-06-07) ------------------------------------------------------------------------ diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 698d9627fa..dc7f255c6e 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3920,7 +3920,10 @@ void Vehicle::UpdateMotionBoatHire() } eax -= velocity; edx = powered_acceleration * 2; - ecx += (eax * edx) / ebx; + if (ebx != 0) + { + ecx += (eax * edx) / ebx; + } } acceleration = ecx; } From 18543caf58d66ad9d5aaf1c9ff92a917af2b7b6b Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 18 Jun 2025 23:40:07 +0200 Subject: [PATCH 2/2] Rename `ecx` to `newAcceleration` --- src/openrct2/ride/Vehicle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index dc7f255c6e..74344fad77 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3909,7 +3909,7 @@ void Vehicle::UpdateMotionBoatHire() int32_t curMass = mass == 0 ? 1 : mass; int32_t eax = ((velocity >> 1) + edx) / curMass; - int32_t ecx = -eax; + int32_t newAcceleration = -eax; if (carEntry->flags & CAR_ENTRY_FLAG_POWERED) { eax = speed << 14; @@ -3922,10 +3922,10 @@ void Vehicle::UpdateMotionBoatHire() edx = powered_acceleration * 2; if (ebx != 0) { - ecx += (eax * edx) / ebx; + newAcceleration += (eax * edx) / ebx; } } - acceleration = ecx; + acceleration = newAcceleration; } // eax = _vehicleMotionTrackFlags; // ebx = _vehicleStationIndex;