spnda / fastgltf

A modern C++17 glTF 2.0 library focused on speed, correctness, and usability
https://fastgltf.readthedocs.io/v0.8.x/
MIT License
275 stars 42 forks source link

gl_viewer crashes on models without textures #36

Closed droettger closed 9 months ago

droettger commented 9 months ago

This line inside the gl_viewer example https://github.com/spnda/fastgltf/blob/main/examples/gl_viewer/gl_viewer.cpp#L421C3-L421C3 will crash with an out-of-bounds access inside the asset.accessors if it->findAttribute("TEXCOORD_0") returns it->attributes.end(). Happens with the Khronos model https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/BrainStem/glTF/BrainStem.gltf

spnda commented 9 months ago

A crash does seem like unintended behaviour but I think what I was trying to do is require a model to have textures. The same applies for the code I wrote that you mentioned in #37.

The example wasn't made to cover absolutely every possibility and is only fairly rudimentary, but I will try and look into adding support for non-textured models, probably by adding a default white texture and just setting their vertex UVs to {0,0}.

That would also simultaneously fix the issue with #37, so I'll close that issue and leave this open to track addition of a default texture to gl_viewer.

I seem to have misunderstood #37, and forgot that the shaders were written with non-textures in mind. So this issue was fairly trivial to fix. Thank you for mentioning this to me.