diff --git a/constants/voxel_constants.h b/constants/voxel_constants.h index 92a874ed..79784e64 100644 --- a/constants/voxel_constants.h +++ b/constants/voxel_constants.h @@ -14,7 +14,12 @@ static const unsigned int MAX_BLOCK_SIZE = 32; static const unsigned int MAX_BLOCK_COUNT_PER_REQUEST = 4 * 4 * 4; -static const unsigned int MAX_LOD = 32; +// 24 should be largely enough. +// With a block size of 32 voxels, and if 1 voxel is 1m large, +// then the largest blocks will span 268,435.456 kilometers, which is roughly 20 times Earth's diameter. +// Using a higher maximum can cause int32 overflows when calculating dimensions. There is no use case for it. +static const unsigned int MAX_LOD = 24; + static const unsigned int MAX_VOLUME_EXTENT = 0x1fffffff; static const unsigned int MAX_VOLUME_SIZE = 2 * MAX_VOLUME_EXTENT; // 1,073,741,822 voxels diff --git a/doc/source/changelog.md b/doc/source/changelog.md index d7ea2458..e9f427e1 100644 --- a/doc/source/changelog.md +++ b/doc/source/changelog.md @@ -40,6 +40,7 @@ Ongoing development - `master` - `VoxelInstanceGenerator`: `EMIT_FROM_FACES` got renamed `EMIT_FROM_FACES_FAST`. `EMIT_FROM_FACES` still exists but is a different algorithm. - `VoxelServer`: `get_stats()` format has changed, check documentation - `VoxelLodTerrain`: `get_statistics()` format has changed: `time_process_update_responses` and `remaining_main_thread_blocks` are no longer available + - `VoxelLodTerrain`: Maximum LOD count was decreased to 24, which is still largely enough. Higher maximums were likely to cause integer overflows. - `VoxelTerrain`: `get_statistics()` format has changed: `time_process_update_responses` and `remaining_main_thread_blocks` are no longer available - `VoxelViewer`: `requires_collisions` is now `true` by default diff --git a/terrain/voxel_lod_terrain.cpp b/terrain/voxel_lod_terrain.cpp index 42430e34..e79c5d9b 100644 --- a/terrain/voxel_lod_terrain.cpp +++ b/terrain/voxel_lod_terrain.cpp @@ -356,6 +356,7 @@ void VoxelLodTerrain::_on_stream_params_changed() { }*/ void VoxelLodTerrain::set_mesh_block_size(unsigned int mesh_block_size) { + // Mesh block size cannot be smaller than data block size, for now mesh_block_size = clamp(mesh_block_size, get_data_block_size(), VoxelConstants::MAX_BLOCK_SIZE); unsigned int po2;