From 71a9def71e8cd73dd4c93fd4f2bc0a096e0a79fb Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 14 Jul 2019 14:28:40 +0300 Subject: WINTERMUTE: Add a warning for off-by-one errors in normalizeAngle() --- engines/wintermute/utils/utils.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'engines/wintermute') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 5afb940cfc..4fad599a2e 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -44,9 +44,22 @@ void BaseUtils::swap(int *a, int *b) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { + float origAngle = angle; + + // The original WME engine checked against 360 here, which is an off-by one + // error, as when normalizing an angle, we expect the number to be between 0 + // and 359 (since 360 is 0). This check has been fixed in ScummVM to 359. If + // the resulting angle is negative, it will be corrected in the while loop + // below. while (angle > 359) { angle -= 360; } + + // Report cases where the above off-by-one error might occur + if (origAngle > 360 && angle < 0) { + warning("BaseUtils::normalizeAngle: off-by-one error detected while normalizing angle %f to %f", origAngle, angle); + } + while (angle < 0) { angle += 360; } -- cgit v1.2.3