Skip to content

Commit

Permalink
Fix warning that index can't be < 0 due to being unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Nov 2, 2023
1 parent b39e61f commit c86f994
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion generators/voxel_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int VoxelGenerator::get_used_channels_mask() const {
VoxelSingleValue VoxelGenerator::generate_single(Vector3i pos, unsigned int channel) {
VoxelSingleValue v;
v.i = 0;
ZN_ASSERT_RETURN_V(channel >= 0 && channel < VoxelBufferInternal::MAX_CHANNELS, v);
ZN_ASSERT_RETURN_V(channel < VoxelBufferInternal::MAX_CHANNELS, v);
// Default slow implementation
// TODO Optimize: a small part of the slowness is caused by the allocator.
// It is not a good use of `VoxelMemoryPool` for such a small size called so often.
Expand Down
2 changes: 1 addition & 1 deletion meshers/blocky/voxel_blocky_library_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void VoxelBlockyLibraryBase::_b_bake() {
}

Ref<Material> VoxelBlockyLibraryBase::get_material_by_index(unsigned int index) const {
ERR_FAIL_INDEX_V(index, _indexed_materials.size(), Ref<Material>());
ZN_ASSERT_RETURN_V(index < _indexed_materials.size(), Ref<Material>());
return _indexed_materials[index];
}

Expand Down
2 changes: 1 addition & 1 deletion meshers/cubes/voxel_mesher_cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ void VoxelMesherCubes::set_material_by_index(Materials id, Ref<Material> materia
}

Ref<Material> VoxelMesherCubes::get_material_by_index(unsigned int i) const {
ERR_FAIL_INDEX_V(i, _materials.size(), Ref<Material>());
ZN_ASSERT_RETURN_V(i < _materials.size(), Ref<Material>());
return _materials[i];
}

Expand Down
8 changes: 4 additions & 4 deletions storage/voxel_buffer_gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ void VoxelBuffer::copy_channel_from_area(
_buffer->copy_from(other->get_buffer(), src_min, src_max, dst_min, channel);
}

void VoxelBuffer::fill(uint64_t defval, unsigned int channel_index) {
void VoxelBuffer::fill(uint64_t defval, int channel_index) {
ZN_DSTACK();
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
_buffer->fill(defval, channel_index);
}

void VoxelBuffer::fill_f(real_t value, unsigned int channel) {
void VoxelBuffer::fill_f(real_t value, int channel) {
ZN_DSTACK();
ERR_FAIL_INDEX(channel, MAX_CHANNELS);
_buffer->fill_f(value, channel);
}

bool VoxelBuffer::is_uniform(unsigned int channel_index) const {
bool VoxelBuffer::is_uniform(int channel_index) const {
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, true);
return _buffer->is_uniform(channel_index);
}
Expand All @@ -80,7 +80,7 @@ void VoxelBuffer::compress_uniform_channels() {
_buffer->compress_uniform_channels();
}

VoxelBuffer::Compression VoxelBuffer::get_channel_compression(unsigned int channel_index) const {
VoxelBuffer::Compression VoxelBuffer::get_channel_compression(int channel_index) const {
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, VoxelBuffer::COMPRESSION_NONE);
return VoxelBuffer::Compression(_buffer->get_channel_compression(channel_index));
}
Expand Down
8 changes: 4 additions & 4 deletions storage/voxel_buffer_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class VoxelBuffer : public RefCounted {
void copy_channel_from_area(
Ref<VoxelBuffer> other, Vector3i src_min, Vector3i src_max, Vector3i dst_min, unsigned int channel);

void fill(uint64_t defval, unsigned int channel_index = 0);
void fill_f(real_t value, unsigned int channel = 0);
void fill(uint64_t defval, int channel_index = 0);
void fill_f(real_t value, int channel = 0);
void fill_area(uint64_t defval, Vector3i min, Vector3i max, unsigned int channel_index) {
_buffer->fill_area(defval, min, max, channel_index);
}

bool is_uniform(unsigned int channel_index) const;
bool is_uniform(int channel_index) const;

void compress_uniform_channels();
Compression get_channel_compression(unsigned int channel_index) const;
Compression get_channel_compression(int channel_index) const;

void downscale_to(Ref<VoxelBuffer> dst, Vector3i src_min, Vector3i src_max, Vector3i dst_min) const;

Expand Down
2 changes: 1 addition & 1 deletion streams/region/voxel_stream_region_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ VoxelStreamRegionFiles::CachedRegion *VoxelStreamRegionFiles::open_region(
const Vector3i region_pos, unsigned int lod, bool create_if_not_found) {
ZN_PROFILE_SCOPE();
ERR_FAIL_COND_V(!_meta_loaded, nullptr);
ERR_FAIL_COND_V(lod < 0, nullptr);
ZN_ASSERT_RETURN_V(lod < constants::MAX_LOD, nullptr);

CachedRegion *cached_region = get_region_from_cache(region_pos, lod);
if (cached_region != nullptr) {
Expand Down

0 comments on commit c86f994

Please sign in to comment.