jkuhlmann / cgltf

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

Ensure that camera has a single consistent type in the file #186

Closed zeux closed 2 years ago

zeux commented 2 years ago

With this change, we now disregard the 'type' field when parsing the camera type, and instead solely rely on the orthographic/perspective keys, and also enforce a single consistent section type during the process.

This ensures that cgltf_camera::data has been filled just once with data that came from a single JSON blob; without this it's possible to fill one struct and then fill another struct which may overwrite some union fields with invalid data, which is a significant issue for extras which contains offsets into the JSON blob.

The reason why we don't need to parse 'type' at all is that the specification says that when type is perspective or orthographic, files without a corresponding JSON section are invalid.

Note that we aren't as strict as we could possibly be, since we don't validate that the "type" field is consistent with the actual JSON structure as it doesn't affect the parsing flow.