diff options
author | lawnjelly <lawnjelly@gmail.com> | 2022-03-07 11:15:45 +0000 |
---|---|---|
committer | lawnjelly <lawnjelly@gmail.com> | 2022-03-07 11:15:45 +0000 |
commit | 0565676893aa761948e2a039c993e1d9d51f31f1 (patch) | |
tree | d2a6d32661f7964a5458b665c884cb528904742d /core/math/vector3.h | |
parent | 6c3170e875bcb2606f08cde731f8b800801ef751 (diff) | |
download | redot-engine-0565676893aa761948e2a039c993e1d9d51f31f1.tar.gz |
Protection for array operator for Vector2 / 3 in DEV builds
A previous PR had changed the array operator to give unbounded access. This could cause crashes where old code depended on this previous safe behaviour.
This PR adds DEV_ASSERT macros for out of bound access to DEV builds, allowing us to quickly identify bugs in calling code, without affecting performance in release or release_debug editor builds.
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r-- | core/math/vector3.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/core/math/vector3.h b/core/math/vector3.h index 89b0095741..b22ebeaf0a 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -59,10 +59,12 @@ struct _NO_DISCARD_ Vector3 { }; _FORCE_INLINE_ const real_t &operator[](const int p_axis) const { + DEV_ASSERT((unsigned int)p_axis < 3); return coord[p_axis]; } _FORCE_INLINE_ real_t &operator[](const int p_axis) { + DEV_ASSERT((unsigned int)p_axis < 3); return coord[p_axis]; } |