Skip to content

GLTF: Fix nasty bug with incorrect buffer indices on export #108302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

I was writing some code with the GLTF module when I noticed that the buffer indices inside of each buffer view was just... completely and totally wrong at export time. Each buffer view had its buffer index set to its own buffer view index.

The problem was caused by this line of code:

r_accessor = bv->buffer = p_state->buffer_views.size();

This line is utter nonsense. The bv->buffer is a buffer index, not a buffer view index. The r_accessor is actually a buffer view index... but it's incorrectly named, so I've also fixed that in this PR.

This bug was hidden thanks to this loop in the export code:

for (GLTFBufferViewIndex i = 0; i < state->buffer_views.size(); i++) {
    state->buffer_views.write[i]->buffer = 0;
}

This code effectively says... ignore the data in the buffer view, use index 0 always instead. That's just... so bad. Complete and utter nonsense. It completely breaks using any buffer other than 0 and breaks all intermediate export code that tries to take a look at what the buffer view's buffer is.

I also renamed _encode_buffer_view to _encode_accessor_into_buffer_view because it's not just buffer views, it also deals heavily with accessor stuff. I also fixed a bug where 16-bit MAT3s were being misaligned (MAT3 is used by nothing in glTF so it went unnoticed until I combed over this code). Also, I improved the comments.

@aaronfranke aaronfranke added this to the 4.5 milestone Jul 5, 2025
@aaronfranke aaronfranke requested a review from a team as a code owner July 5, 2025 06:50
@aaronfranke aaronfranke changed the title GLTF: Fix nasty bug with incorrect buffer indices GLTF: Fix nasty bug with incorrect buffer indices on export Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants