azul3d / engine

Azul3D - A 3D game engine written in Go!
https://azul3d.org
Other
606 stars 54 forks source link

runtime error: slice bounds out of range in .../engine/gfx/gl2/device.go :395 #170

Closed pahansen95 closed 7 years ago

pahansen95 commented 7 years ago

I am getting an index out of range panic

panic: runtime error: slice bounds out of range

goroutine 51 [running, locked to thread]:
azul3d.org/engine/gfx/gl2.(*device).queryYield(0xc0420bc1a0, 0x4f9de4)
        C:/Go/Workspace/src/azul3d.org/engine/gfx/gl2/device.go:395 +0x4b8
azul3d.org/engine/gfx/gl2.(*device).queryWait(0xc0420bc1a0)
        C:/Go/Workspace/src/azul3d.org/engine/gfx/gl2/device.go:412 +0x48
azul3d.org/engine/gfx/gl2.(*device).hookedRender.func1(0xc0421b1f10)
        C:/Go/Workspace/src/azul3d.org/engine/gfx/gl2/device.go:340 +0xdb
azul3d.org/engine/gfx/window.(*glfwWindow).run(0xc0420c8160)
        C:/Go/Workspace/src/azul3d.org/engine/gfx/window/glfwwindow.go:684 +0x5ac
created by azul3d.org/engine/gfx/window.doNew
        C:/Go/Workspace/src/azul3d.org/engine/gfx/window/glfwwindow.go:821 +0x396

I altered the code to print out the values for r.pending.queries and query index and this is what i saw (respectively)

3 0
[...]
3 0
2 0
1 1
slimsag commented 7 years ago

Hi @CommodoreCrunch99

Those index values inside of r.pending.queries are arbitrary numbers (like pointers) generated by OpenGL at runtime, so they aren't super useful for figuring out what went wrong here. Can you find a minimal program that reproduces the issue? That'd be the best place for me to start on figuring out what causes this.

pahansen95 commented 7 years ago

Please see this github repo

https://github.com/CommodoreCrunch99/IssueExample

It is the code I am using stripped of everything referencing packages from another project I made.

slimsag commented 7 years ago

Thanks!

I've found out that commenting out all of your OcclusionTest = true lines in mainWindow.go temporarily works around the issue (although this obviously disables occlusion testing).

slimsag commented 7 years ago

Hi @CommodoreCrunch99 I found the cause was a simple bug where we incorrectly assumed the index was correct while removing things from the slice. Basically, the slice length would change when we removed the first element, so the second removal would result in the 'slice bounds out of range' panic seen here. I've fixed in https://github.com/azul3d/engine/commit/eb48fbeb6d97ddebb823269e5cf41ae0af903765 and your example seems to work now.