go-gl / gl

Go bindings for OpenGL (generated via glow)
MIT License
1.07k stars 74 forks source link

gl.BindVertexArray causes an occasional crash #107

Closed rishabh-bector closed 6 years ago

rishabh-bector commented 6 years ago

Sometimes when I build and run my code, it crashes with the following stack trace:

Exception 0xc0000005 0x0 0x1580 0x69bf40c9
PC=0x69bf40c9

runtime: unknown pc 0x69bf40c9
stack: frame={sp:0x47afe58, fp:0x0} stack=[0x0,0x47afeb0)
00000000047afd58:  0000000000000400  0000000000000008
00000000047afd68:  00000000047afd90  0000000000000001
00000000047afd78:  0000000000000000  0203000000000000
00000000047afd88:  0000000000000090  0000000000000084
00000000047afd98:  000000c000098090  0000000801000006
00000000047afda8:  0000000100000084  00000000047afdf8
00000000047afdb8:  0000000000418167 <runtime.(*mcentral).grow+327>  000000c000008d48
00000000047afdc8:  00000000004592ee <runtime.asmstdcall+94>  0000000000000010
00000000047afdd8:  000000c000098090  0000000000000042
00000000047afde8:  000000c0000e9350  0000000000000000
00000000047afdf8:  00000000047afe40  0000000000417aca <runtime.(*mcentral).cacheSpan+474>
00000000047afe08:  00000000001c9ee0  0000000000000000
00000000047afe18:  0000000000000000  0000001600000000
00000000047afe28:  0000000000002000  00000000001c9ee0
00000000047afe38:  000000001881b0d0  00000000047afe70
00000000047afe48:  0000000000417793 <runtime.(*mcache).refill+163>  000000c000008d48
00000000047afe58: <00000000004571b3 <runtime.asmcgocall+115>  0000000000000015
00000000047afe68:  000000c000002900  00000000047afe90
00000000047afe78:  0000000000452f49 <runtime.(*mcache).nextFree.func1+57>  00000000001c06a0
00000000047afe88:  0000000000000650  000000c000002180
00000000047afe98:  000000000045595b <runtime.systemstack+107>  0000000000432850 <runtime.mstart+0>
00000000047afea8:  0000000000000000
runtime: unknown pc 0x69bf40c9
stack: frame={sp:0x47afe58, fp:0x0} stack=[0x0,0x47afeb0)
00000000047afd58:  0000000000000400  0000000000000008
00000000047afd68:  00000000047afd90  0000000000000001
00000000047afd78:  0000000000000000  0203000000000000
00000000047afd88:  0000000000000090  0000000000000084
00000000047afd98:  000000c000098090  0000000801000006
00000000047afda8:  0000000100000084  00000000047afdf8
00000000047afdb8:  0000000000418167 <runtime.(*mcentral).grow+327>  000000c000008d48
00000000047afdc8:  00000000004592ee <runtime.asmstdcall+94>  0000000000000010
00000000047afdd8:  000000c000098090  0000000000000042
00000000047afde8:  000000c0000e9350  0000000000000000
00000000047afdf8:  00000000047afe40  0000000000417aca <runtime.(*mcentral).cacheSpan+474>
00000000047afe08:  00000000001c9ee0  0000000000000000
00000000047afe18:  0000000000000000  0000001600000000
00000000047afe28:  0000000000002000  00000000001c9ee0
00000000047afe38:  000000001881b0d0  00000000047afe70
00000000047afe48:  0000000000417793 <runtime.(*mcache).refill+163>  000000c000008d48
00000000047afe58: <00000000004571b3 <runtime.asmcgocall+115>  0000000000000015
00000000047afe68:  000000c000002900  00000000047afe90
00000000047afe78:  0000000000452f49 <runtime.(*mcache).nextFree.func1+57>  00000000001c06a0
00000000047afe88:  0000000000000650  000000c000002180
00000000047afe98:  000000000045595b <runtime.systemstack+107>  0000000000432850 <runtime.mstart+0>
00000000047afea8:  0000000000000000

goroutine 1 [syscall]:
github.com/go-gl/gl/v4.1-core/gl._Cfunc_glowBindVertexArray(0x69bf40c0, 0xc000000001)
        _cgo_gotypes.go:3229 +0x4c
github.com/go-gl/gl/v4.1-core/gl.BindVertexArray(0xc000000001)
        C:/Users/becto/go/src/github.com/go-gl/gl/v4.1-core/gl/package.go:8588 +0x3c
rapidengine.(*Child2D).BindChild(0x92d160)
        C:/Users/becto/go/src/rapidengine/child2D.go:79 +0x36
rapidengine.(*Child2D).PreRender(0x92d160, 0x796c00, 0xc0000dc000)
        C:/Users/becto/go/src/rapidengine/child2D.go:55 +0xab
rapidengine.(*Renderer).PreRenderChildren(0x92d060)
        C:/Users/becto/go/src/rapidengine/render.go:61 +0x84
rapidengine.(*Engine).InitializeRenderer(0x92d060)
        C:/Users/becto/go/src/rapidengine/engine.go:47 +0x34
main.main()
        C:/Users/becto/go/src/Hellion/main.go:63 +0x59f
rax     0x0
rbx     0xc0000e9a28
rcx     0x1
rdi     0xc0000e9a28
rsi     0xc000002900
rbp     0xc0000e99e0
rsp     0x47afe58
r8      0xc000002180
r9      0x0
r10     0x6
r11     0x37c47a4
r12     0x37c47a4
r13     0x78fb77
r14     0x0
r15     0x0
rip     0x69bf40c9
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

Interestingly, if I run my code enough times, it eventually works without immediately crashing. The only similar issue I could find to this was: https://github.com/veandco/go-sdl2/issues/78.

I'm running Go 1.11 Windows x64.

Reproducing might be tricky; I'm building and running this code: https://github.com/rishabh-bector/Hellion

Using this game engine which I'm writing: https://github.com/rishabh-bector/RapidEngine

This is a very strange issue.

rishabh-bector commented 6 years ago

Update: This happens when you forget to runtime.LockOSThread().