Git Product home page Git Product logo

Comments (8)

Zylann avatar Zylann commented on August 16, 2024 1

Oh. Yeah that condition should be the opposite. Looks like I never used this function either xD Thanks for pointing these mistakes!

from godot_voxel.

afonsolage avatar afonsolage commented on August 16, 2024

There is a similar problem (I think so) on other VoxelBuffer::copy_from. Given:

void VoxelBuffer::copy_from(const VoxelBuffer &other, Vector3i src_min, Vector3i src_max, Vector3i dst_min, unsigned int channel_index) {
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
Channel &channel = _channels[channel_index];
const Channel &other_channel = other._channels[channel_index];
Vector3i::sort_min_max(src_min, src_max);
src_min.clamp_to(Vector3i(0, 0, 0), other._size);
src_max.clamp_to(Vector3i(0, 0, 0), other._size + Vector3i(1, 1, 1));
dst_min.clamp_to(Vector3i(0, 0, 0), _size);
Vector3i area_size = src_max - src_min;
//Vector3i dst_max = dst_min + area_size;
if (area_size == _size) {
copy_from(other, channel_index);
} else {
if (other_channel.data) {
if (channel.data == NULL) {
create_channel(channel_index, _size, channel.defval);
}
// Copy row by row
Vector3i pos;
for (pos.z = 0; pos.z < area_size.z; ++pos.z) {
for (pos.x = 0; pos.x < area_size.x; ++pos.x) {
// Row direction is Y
unsigned int src_ri = other.index(pos.x + src_min.x, pos.y + src_min.y, pos.z + src_min.z);
unsigned int dst_ri = index(pos.x + dst_min.x, pos.y + dst_min.y, pos.z + dst_min.z);
memcpy(&channel.data[dst_ri], &other_channel.data[src_ri], area_size.y * sizeof(uint8_t));
}
}
} else if (channel.defval != other_channel.defval) {
if (channel.data == NULL) {
create_channel(channel_index, _size, channel.defval);
}
// Set row by row
Vector3i pos;
for (pos.z = 0; pos.z < area_size.z; ++pos.z) {
for (pos.x = 0; pos.x < area_size.x; ++pos.x) {
unsigned int dst_ri = index(pos.x + dst_min.x, pos.y + dst_min.y, pos.z + dst_min.z);
memset(&channel.data[dst_ri], other_channel.defval, area_size.y * sizeof(uint8_t));
}
}
}
}
}

This line:

if (area_size == _size) {

Should be if (other._size == _size) { because we can only the other VoxelBuffer::copy_from only if the other and current one size's are equals. Even if the area_size is equals to the destiny of the copy, we won't provide any offset, so it'll always fail.

Should I open another issue or since their are related, we can keep both here?

from godot_voxel.

Zylann avatar Zylann commented on August 16, 2024

Actually copy_from without arguments can only be used if other._size == _size AND if the area specified covers the whole block anyways.

from godot_voxel.

afonsolage avatar afonsolage commented on August 16, 2024

But what if I want to copy an area that is the same size of target buffer? It will evaluate to true and will crash on another copy_from, since there is the following check: ERR_FAIL_COND(other._size == _size);

Let me give an use case. Let's say I have a padded voxel buffer of size (18, 18, 18). What if I want to copy only the "original-nonpadded-area" of the buffer into another buffer of size(16, 16, 16)?

I can just call the function copy_from as follows:

shoter_buffer->copy_from(**padded_buffer, Vector3i(buffer_padding), padded_buffer->get_size() - buffer_padding, Vector3i(), channel);

But it'll crash, because since the area_size == _size it'll try to make a direct copy using the other copy_from. But if we change the check to other._size == _size it'll still do the area copy and will work fine.

from godot_voxel.

Zylann avatar Zylann commented on August 16, 2024

Correcting your example, should be 2*padding:

padded_buffer->get_size() - 2 * buffer_padding

Otherwise yeah sorry, what I meant is that if the two buffers have the same size AND the desired area is also that same size, then the copy_from without area could be used. In any other case, it should continue with the area method.

from godot_voxel.

afonsolage avatar afonsolage commented on August 16, 2024

So the correct way should be:

 if (area_size == _size && _other.size == _size) { 

Is that so?

Also, thanks for pointing me out that error, you fixed a future bug on my voxel lighting code 😄

from godot_voxel.

Zylann avatar Zylann commented on August 16, 2024

Yes that check would be correct.
Good to hear :D

from godot_voxel.

Zylann avatar Zylann commented on August 16, 2024

Fixed in 3074f82

from godot_voxel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.