jpaver / opengametools

A set of open c++ game development tools that are lightweight, easy-to-integrate and free to use. Currently hosting a magicavoxel .vox full scene loader.
MIT License
373 stars 35 forks source link

Added asserts to catch saving and loading of a model with zero size #47

Closed dougbinks closed 1 year ago

dougbinks commented 1 year ago

Currently ogt_vox.h will assert on loading a model with 0 size when reading the CHUNK_ID_XYZI at line:

1320 ogt_assert(size_x && size_y && size_z, "expected a SIZE chunk before XYZI chunk");

https://github.com/jpaver/opengametools/blob/master/src/ogt_vox.h#L1320

This can be a little confusing, as the actual error can be due to the model having zero size. In addition I discovered this by saving out a .vox file with a model of zero size, so here I have also added an assert for this case in the write code.

Whilst MV appears to handle loading a 0 size model you can't create one using it's UI, so it's likely still good practice to assert on this.