Check AABB size before using it

This commit is contained in:
Marc Gilleron 2021-10-27 19:49:37 +01:00
parent 97f6765831
commit 3133834a17
6 changed files with 10 additions and 0 deletions

View File

@ -61,6 +61,7 @@ Ongoing development - `master`
- `VoxelStreamBlockFiles`: fixed warning about channels always shown in the scene tree
- `VoxelStreamSQLite`: fixed blocks above LOD0 being saved at wrong locations, causing them to be reloaded often floating in the air
- Fix some crashes occurring when all PoolVector allocs are in use (Godot 3.x limitation). It will print errors instead, but crashes can still occur inside Godot's code as it's not often checking for this
- Fix some crashes occurring when negative sizes are sent to AABB function parameters
09/05/2021 - `godot3.3`

View File

@ -597,6 +597,7 @@ static Array separate_floating_chunks(VoxelTool &voxel_tool, Box3i world_box, No
Array VoxelToolLodTerrain::separate_floating_chunks(AABB world_box, Node *parent_node) {
ERR_FAIL_COND_V(_terrain == nullptr, Array());
ERR_FAIL_COND_V(!is_valid_size(world_box.size), Array());
Ref<VoxelMesher> mesher = _terrain->get_mesher();
Array materials;
materials.append(_terrain->get_material());

View File

@ -229,6 +229,7 @@ void VoxelToolTerrain::run_blocky_random_tick(AABB voxel_area, int voxel_count,
ERR_FAIL_COND(callback.is_null());
ERR_FAIL_COND(batch_count <= 0);
ERR_FAIL_COND(voxel_count < 0);
ERR_FAIL_COND(!is_valid_size(voxel_area.size));
if (voxel_count == 0) {
return;
@ -327,6 +328,7 @@ void VoxelToolTerrain::run_blocky_random_tick(AABB voxel_area, int voxel_count,
void VoxelToolTerrain::for_each_voxel_metadata_in_area(AABB voxel_area, Ref<FuncRef> callback) {
ERR_FAIL_COND(_terrain == nullptr);
ERR_FAIL_COND(callback.is_null());
ERR_FAIL_COND(!is_valid_size(voxel_area.size));
const Box3i voxel_box = Box3i(Vector3i(voxel_area.position), Vector3i(voxel_area.size));
ERR_FAIL_COND(!is_area_editable(voxel_box));

View File

@ -2253,6 +2253,7 @@ void VoxelLodTerrain::_b_save_modified_blocks() {
}
void VoxelLodTerrain::_b_set_voxel_bounds(AABB aabb) {
ERR_FAIL_COND(!is_valid_size(aabb.size));
// TODO Please Godot, have an integer AABB!
set_voxel_bounds(Box3i(aabb.position.round(), aabb.size.round()));
}

View File

@ -1353,6 +1353,7 @@ void VoxelTerrain::_b_save_block(Vector3 p_block_pos) {
}
void VoxelTerrain::_b_set_bounds(AABB aabb) {
ERR_FAIL_COND(!is_valid_size(aabb.size));
// TODO Please Godot, have an integer AABB!
set_bounds(Box3i(aabb.position.round(), aabb.size.round()));
}

View File

@ -154,6 +154,10 @@ inline Vector3 fract(const Vector3 &p) {
return Vector3(fract(p.x), fract(p.y), fract(p.z));
}
inline bool is_valid_size(const Vector3 &s) {
return s.x >= 0 && s.y >= 0 && s.z >= 0;
}
// inline bool is_power_of_two(int i) {
// return i & (i - 1);
// }