[Scummvm-git-logs] scummvm master -> 2719d826e2f454f9539a4f7eafdb69134d65d302

fracturehill noreply at scummvm.org
Tue Jan 23 20:17:29 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
2719d826e2 NANCY: Second attempt to fix RaycastPuzzle on ARM


Commit: 2719d826e2f454f9539a4f7eafdb69134d65d302
    https://github.com/scummvm/scummvm/commit/2719d826e2f454f9539a4f7eafdb69134d65d302
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-01-23T21:17:10+01:00

Commit Message:
NANCY: Second attempt to fix RaycastPuzzle on ARM

This undoes the last attempt at a fix, and makes changes
that remove the undefined behavior caused by casting
negative floats to unsigned int.

Changed paths:
    engines/nancy/action/puzzle/raycastpuzzle.cpp


diff --git a/engines/nancy/action/puzzle/raycastpuzzle.cpp b/engines/nancy/action/puzzle/raycastpuzzle.cpp
index 5f7a5cde2b9..912dab13977 100644
--- a/engines/nancy/action/puzzle/raycastpuzzle.cpp
+++ b/engines/nancy/action/puzzle/raycastpuzzle.cpp
@@ -1939,7 +1939,7 @@ void RaycastPuzzle::drawMaze() {
 
 	for (int floorY = viewportCenterY + 5; floorY < viewBounds.bottom; ++floorY) {
 		int ceilingY = viewportCenterY - (floorY - viewportCenterY) + 1;
-		int32 	floorSrcFracX, floorSrcFracY,
+		uint32 	floorSrcFracX, floorSrcFracY,
 				ceilingSrcFracX, ceilingSrcFracY,
 				floorSrcIncrementX, floorSrcIncrementY,
 				ceilingSrcIncrementX, ceilingSrcIncrementY;
@@ -1961,17 +1961,18 @@ void RaycastPuzzle::drawMaze() {
 			float ceilingLeftY  =	_sinTable[leftAngle]  * -(ceilingViewAngle / _cosTable[_leftmostAngle])  + (float)_playerX;
 			float ceilingRightY =	_sinTable[rightAngle] * -(ceilingViewAngle / _cosTable[_rightmostAngle]) + (float)_playerX;
 
-			floorSrcFracX	= (uint32)((double)floorLeftX	* 65536.0);
-			floorSrcFracY	= (uint32)((double)floorLeftY	* 65536.0);
+			// Casting between negative float and uint is undefined behavior, hence the cast to signed int first
+			floorSrcFracX	= (uint32)((int32)(floorLeftX	* 65536.0));
+			floorSrcFracY	= (uint32)((int32)(floorLeftY	* 65536.0));
 
-			ceilingSrcFracX = (uint32)((double)ceilingLeftX * 65536.0);
-			ceilingSrcFracY = (uint32)((double)ceilingLeftY * 65536.0);
+			ceilingSrcFracX = (uint32)((int32)(ceilingLeftX * 65536.0));
+			ceilingSrcFracY = (uint32)((int32)(ceilingLeftY * 65536.0));
 
-			floorSrcIncrementX 		= (uint32)((double)((floorRightX	- floorLeftX)	/ (float)viewBounds.width()) * 65536.0);
-			floorSrcIncrementY 		= (uint32)((double)((floorRightY	- floorLeftY)	/ (float)viewBounds.width()) * 65536.0);
+			floorSrcIncrementX 		= (uint32)((int32)(((floorRightX	- floorLeftX)	/ (float)viewBounds.width()) * 65536.0));
+			floorSrcIncrementY 		= (uint32)((int32)(((floorRightY	- floorLeftY)	/ (float)viewBounds.width()) * 65536.0));
 
-			ceilingSrcIncrementX 	= (uint32)((double)((ceilingRightX	- ceilingLeftX) / (float)viewBounds.width()) * 65536.0);
-			ceilingSrcIncrementY 	= (uint32)((double)((ceilingRightY	- ceilingLeftY) / (float)viewBounds.width()) * 65536.0);
+			ceilingSrcIncrementX 	= (uint32)((int32)(((ceilingRightX	- ceilingLeftX) / (float)viewBounds.width()) * 65536.0));
+			ceilingSrcIncrementY 	= (uint32)((int32)(((ceilingRightY	- ceilingLeftY) / (float)viewBounds.width()) * 65536.0));
 		}
 
 		for (int x = viewBounds.left; x < viewBounds.right; ++x) {




More information about the Scummvm-git-logs mailing list