From af205cf58283e72f5f6ca45e6d8ff5761148e956 Mon Sep 17 00:00:00 2001 From: Chris Branch Date: Fri, 5 Oct 2018 22:59:06 +0100 Subject: [PATCH] Fix undefined behaviour converting 3D postest registers If the position test register is negative, conversion to unsigned integer is undefined. This breaks games on arm64 where the behaviour is defined as 'truncate to zero'. Converting to a signed integer first guarantees the intended behaviour. --- desmume/src/gfx3d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index a4e532614..ea670f9dc 100755 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -1946,7 +1946,7 @@ void gfx3d_glAlphaFunc(u32 v) u32 gfx3d_glGetPosRes(const size_t index) { - return (u32)(PTcoords[index] * 4096.0f); + return (u32)(s32)(PTcoords[index] * 4096.0f); } //#define _3D_LOG_EXEC