Skip to content
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

gltf.parse assumes 4-byte aligned little endian data #9

Closed
fabioarnold opened this issue Feb 5, 2024 · 3 comments
Closed

gltf.parse assumes 4-byte aligned little endian data #9

fabioarnold opened this issue Feb 5, 2024 · 3 comments

Comments

@fabioarnold
Copy link
Contributor

fabioarnold commented Feb 5, 2024

Ran into this because I used @embedFile to embed my glb model. Unfortunately, according to ziglang/zig#4680 it's currently not possible to specify alignment for @embedFile.

I know it's simpler to just assume these preconditions (and it's probably faster to cast to u32 pointers). But it would be nice to at least have an assertion for alignment and endianness to help with the error search.

The safer/correct but also slower way would be to treat the data as a byte stream and use something like this:

var reader = std.io.fixedBufferStream(data).reader();
const my_int = reader.readInt(u32, .little);

Edit: nvm, saw in the glTF spec that 4-byte alignment is a requirement. So at least an assertion would be nice.

@kooparse
Copy link
Owner

Thanks, I will see what I can do on this; I'll let you know.

@fabioarnold
Copy link
Contributor Author

Hey, thanks for considering this. And thanks for the great library. It's awesome!

I added align(4) to relevant places here: #10
Now type-checking will complain when you want to pass unaligned data to gltf.parse. What do you think?

I don't know if it's worth it to handle big endian. I think it's a pretty rare these days. I'm targeting wasm, btw.

@kooparse
Copy link
Owner

Merged; thanks a lot! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants