diff options
author | lawnjelly <lawnjelly@gmail.com> | 2022-03-23 08:06:29 +0000 |
---|---|---|
committer | lawnjelly <lawnjelly@gmail.com> | 2022-03-23 09:19:26 +0000 |
commit | 109d08c84ae72c74b48471efd8581ab740b27888 (patch) | |
tree | 24c001c9c927a0c2d6d1b796661e30696228b3c2 /core/math/bvh_structs.inc | |
parent | cd2e7fbc57345370d03854d225208ff480ba6969 (diff) | |
download | redot-engine-109d08c84ae72c74b48471efd8581ab740b27888.tar.gz |
Add protective checks for invalid handle use in BVH
Adds DEV_ASSERTS that will halt at runtime if the BVH is misused with invalid IDs, and adds ERR_FAIL macros to prevent calling with invalid IDs.
Any such misuse is a bug in the physics, but this should flag any errors quickly.
Diffstat (limited to 'core/math/bvh_structs.inc')
-rw-r--r-- | core/math/bvh_structs.inc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/core/math/bvh_structs.inc b/core/math/bvh_structs.inc index b0d9ae3615..58c8f0479a 100644 --- a/core/math/bvh_structs.inc +++ b/core/math/bvh_structs.inc @@ -60,11 +60,23 @@ private: public: // accessors - BVHABB_CLASS &get_aabb(uint32_t p_id) { return aabbs[p_id]; } - const BVHABB_CLASS &get_aabb(uint32_t p_id) const { return aabbs[p_id]; } + BVHABB_CLASS &get_aabb(uint32_t p_id) { + BVH_ASSERT(p_id < MAX_ITEMS); + return aabbs[p_id]; + } + const BVHABB_CLASS &get_aabb(uint32_t p_id) const { + BVH_ASSERT(p_id < MAX_ITEMS); + return aabbs[p_id]; + } - uint32_t &get_item_ref_id(uint32_t p_id) { return item_ref_ids[p_id]; } - const uint32_t &get_item_ref_id(uint32_t p_id) const { return item_ref_ids[p_id]; } + uint32_t &get_item_ref_id(uint32_t p_id) { + BVH_ASSERT(p_id < MAX_ITEMS); + return item_ref_ids[p_id]; + } + const uint32_t &get_item_ref_id(uint32_t p_id) const { + BVH_ASSERT(p_id < MAX_ITEMS); + return item_ref_ids[p_id]; + } bool is_dirty() const { return dirty; } void set_dirty(bool p) { dirty = p; } |