From ba746435949e7ff1c4587390d34bc9d175a6f71a Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Mon, 6 Jun 2022 16:58:21 +0100 Subject: [PATCH] Force unsigned behaviour for bitfield enums Some compilers (notably MSVC) were using signed values for bitfield enums. This was causing problems where 2 bits were used to store 4 or less enum values, where they were being treated as negative numbers. This PR explicitly requests these enums to be treated as unsigned values. --- core/math/transform_interpolator.h | 2 +- scene/main/node.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/math/transform_interpolator.h b/core/math/transform_interpolator.h index cbe1c6b5603..aff9d2c1a91 100644 --- a/core/math/transform_interpolator.h +++ b/core/math/transform_interpolator.h @@ -50,7 +50,7 @@ class Transform; class TransformInterpolator { public: - enum Method { + enum Method : unsigned int { INTERP_LERP, INTERP_SLERP, INTERP_SCALED_SLERP, diff --git a/scene/main/node.h b/scene/main/node.h index 5d20f9e59f9..e7edd731c17 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -48,14 +48,18 @@ class Node : public Object { OBJ_CATEGORY("Nodes"); public: - enum PauseMode { + // N.B. Any enum stored as a bitfield should + // be specified as UNSIGNED to work around + // some compilers trying to store it as signed, + // and requiring 1 more bit than necessary. + enum PauseMode : unsigned int { PAUSE_MODE_INHERIT, PAUSE_MODE_STOP, PAUSE_MODE_PROCESS }; - enum PhysicsInterpolationMode { + enum PhysicsInterpolationMode : unsigned int { PHYSICS_INTERPOLATION_MODE_INHERIT, PHYSICS_INTERPOLATION_MODE_OFF,