fogleman / fauxgl

Software-only 3D renderer written in Go.
MIT License
870 stars 69 forks source link

NewVoxelMesh: index out of range panic #27

Closed torbensky closed 1 year ago

torbensky commented 1 year ago

I've been encountering an "index out of range" panic when creating a VoxelMesh similar to the following:

voxels := []Voxel{
        {X: 0, Y: 2, Z: 0}, {X: 1, Y: 0, Z: 0},
        {X: 0, Y: 1, Z: 0}, {X: 1, Y: 1, Z: 0},
        {X: 0, Y: 2, Z: 0}, {X: 1, Y: 2, Z: 0},
        {X: 1, Y: 1, Z: 1},
    }
vm := NewVoxelMesh(voxels)

It seems to generally happen with any "plane" of voxels with a few more voxels above it.

This mesh (and other similar ones) reproduces the following error consistently:

panic: runtime error: index out of range [-1] [recovered] panic: runtime error: index out of range [-1] ... github.com/fogleman/fauxgl.combineVoxelFaces({0xc000114280?, 0x3, 0x1?}) /projects/github.com/fogleman/fauxgl/voxel.go:179 +0x545 github.com/fogleman/fauxgl.NewVoxelMesh({0xc00008ddd8, 0x7, 0x7?}) /projects/github.com/fogleman/fauxgl/voxel.go:93 +0x273

I am not sure if this is user error on my part or a bug as I'm very new to this library and the concept of voxel meshes.

torbensky commented 1 year ago

argh, I realized my example had a typo and had an overlapping voxel... and of course, fixing that doesn't reproduce the bug... so perhaps my original issue was also an overlapping voxel.

I'll double-check all that and close this issue if it is just user error on my part. I expect that overlapping voxels is not a valid use case.

torbensky commented 1 year ago

Oof yeah, as far as I can tell this has only been happening when I have overlapping voxels added to the same mesh and I'm assuming this is not a valid use case.

I'll close the issue. Sorry for the false alarm.