From 45464cddeb04e431d7afe28a9b6e84d395a3881c Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 9 Feb 2021 19:13:38 +0100 Subject: [PATCH 1/2] Fix #12939: divide-by-0 in Vehicle::UpdateMotionDodgems() --- src/openrct2/ride/Vehicle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index a8ed2e8b5e..f12ef1a1de 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6476,7 +6476,8 @@ int32_t Vehicle::UpdateMotionDodgems() } _eax -= velocity; _eax *= powered_acceleration * 2; - _eax /= ebx; + if (ebx != 0) + _eax /= ebx; acceleration = _eax - eax; return _vehicleMotionTrackFlags; From 25b26e769d851e30a3f94ca6ebe87ea5b25311c0 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 9 Feb 2021 20:32:05 +0100 Subject: [PATCH 2/2] Rename ebx to momentum --- 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 f12ef1a1de..f8bd91c218 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -6468,7 +6468,7 @@ int32_t Vehicle::UpdateMotionDodgems() return _vehicleMotionTrackFlags; } - int32_t ebx = (speed * mass) >> 2; + int32_t momentum = (speed * mass) >> 2; int32_t _eax = speed << 14; if (HasUpdateFlag(VEHICLE_UPDATE_FLAG_REVERSING_SHUTTLE)) { @@ -6476,8 +6476,8 @@ int32_t Vehicle::UpdateMotionDodgems() } _eax -= velocity; _eax *= powered_acceleration * 2; - if (ebx != 0) - _eax /= ebx; + if (momentum != 0) + _eax /= momentum; acceleration = _eax - eax; return _vehicleMotionTrackFlags;