tetra3d icon indicating copy to clipboard operation
tetra3d copied to clipboard

panic: index out of range

Open xackery opened this issue 2 years ago • 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/[email protected]/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

xackery avatar Jul 08 '22 03:07 xackery

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))
			}

xackery avatar Jul 08 '22 03:07 xackery

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?

SolarLune avatar Jul 09 '22 04:07 SolarLune

@xackery

khaelou avatar Feb 04 '23 10:02 khaelou

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.

xackery avatar Feb 04 '23 21:02 xackery