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.
This commit is contained in:
parent
6c3170e875
commit
0565676893
5 changed files with 33 additions and 0 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#ifndef VECTOR3I_H
|
||||
#define VECTOR3I_H
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
|
||||
class String;
|
||||
|
|
@ -54,10 +55,12 @@ struct _NO_DISCARD_ Vector3i {
|
|||
};
|
||||
|
||||
_FORCE_INLINE_ const int32_t &operator[](const int p_axis) const {
|
||||
DEV_ASSERT((unsigned int)p_axis < 3);
|
||||
return coord[p_axis];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int32_t &operator[](const int p_axis) {
|
||||
DEV_ASSERT((unsigned int)p_axis < 3);
|
||||
return coord[p_axis];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue