jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.44k stars 136 forks source link

cgltf_image::buffer_view::data is null #183

Closed Trider12 closed 2 months ago

Trider12 commented 2 years ago

I'm loading some glb files and cgltf_image::buffer_view::data is null:

image

I'm able to get the data by doing:

void* data = texture->image->buffer_view->buffer->data + texture->image->buffer_view->offset;

But this feels like not the intended way of doing this.

jkuhlmann commented 2 years ago

There is actually a comment in the definition of cgltf_buffer_view about this:

    void* data; /* overrides buffer->data if present, filled by extensions */

And then there is a helper function which does exactly what you are doing: cgltf_buffer_view_data(). It doesn't seem to be exposed externally though. Maybe we should do that. It would help you, correct?

Trider12 commented 2 years ago

Ah, I saw that comment, but still miss-interpreted the purpose of the cgltf_buffer_view::data field. I feel that the naming is a bit confusing, but understand that altering it is a breaking change, so is not possible.

But I did actually end up writing a function identical to cgltf_buffer_view_data() myself, so maybe exposing it is a good idea.