SolarLune/tetra3d

panic: index out of range

xackery opened this issue · 4 comments


goroutine 1 [running, locked to thread]:
github.com/solarlune/tetra3d.LoadGLTFData({0xc00044c000, 0x1d81b, 0x1d81b}, 0x0)
        /Users/xackery/Documents/code/go/pkg/mod/github.com/solarlune/tetra3d@v0.9.0/gltf.go:162 +0x8e7a
exit status 2

seems:

newMat.TexturePath = doc.Images[*doc.Textures[texture.Index].Source].URI

is missing sanity checks and making assumptions, I'm using something similar to https://github.com/qmuntal/gltf/blob/80d3922a76d3e24371f8c99e0d213ecc8dae3ffe/modeler/example_test.go#L35 to generate a gltf and it is cutting corners on some steps, and causing tetra3d to panic non-gracefully

A fix could be something like:

if int(texture.Index) > len(doc.Images) {
				return nil, fmt.Errorf("texture index %d is beyond length of images (%d)", texture.Index, len(doc.Images))
			}

Hello! I'm not certain I understand - are you generating a GLTF file and setting the texture's index to be a value that doesn't exist?

Hi @SolarLune and @khaelou,
Yes,
I am a converting from a propietary format to a GLTF, and not every the texture's index is properly referred to in doc.Images array, and I'll have to manually sanity check this or recover from panics with the current design.