go-gl / gl

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

Runtime Exception when calling gl.UseProgram #94

Closed janivanecky closed 6 years ago

janivanecky commented 6 years ago

Hey,

I'm encountering following runtime error after few seconds of running my application:

Exception 0xc0000005 0x0 0x1230 0x5dbe0f79
PC=0x5dbe0f79

runtime: unknown pc 0x5dbe0f79
stack: frame={sp:0x522fe08, fp:0x0} stack=[0x5031ed0,0x522fed0)
000000000522fd08:  00007ffc924d01f8  000000000522fd30
000000000522fd18:  0000000000424262 <runtime.newAllocBits+50>  0000000000000200
000000000522fd28:  0000000010030050  0000000000000001
000000000522fd38:  0000000000412ff0 <runtime.heapBits.initSpan+256>  0000000000450ec0 <runtime.cgocallback_gofunc+0>
000000000522fd48:  0000000000000000  000000c042296000
000000000522fd58:  00007ffc924bbf2e  0000000000388000
000000000522fd68:  00000000054308c0  000000000522fdd0
000000000522fd78:  000000c000000000  0000000000000001
000000000522fd88:  0000000002859c38  0000000000450ec0 <runtime.cgocallback_gofunc+0>
000000000522fd98:  0000000000000000  0000000000000040
000000000522fda8:  00000000005d2e20  00000319000001c1
000000000522fdb8:  000000c0423ab6f0  000000c042056000
000000000522fdc8:  00000000005d7074  00000319000001c1
000000000522fdd8:  0000000000002000  0000000002858170
000000000522fde8:  000000c0423ab6e8  000000c0423ab6f0
000000000522fdf8:  000000c042056000  000000c0423ab6f0
000000000522fe08: <0000000000450e13 <runtime.asmcgocall+115>  0000000000000005
000000000522fe18:  000000c042056000  000000000522fe40
000000000522fe28:  000000000044c949 <runtime.(*mcache).nextFree.func1+57>  00000000001c0000
000000000522fe38:  0000000000000960  000000c042038000
000000000522fe48:  000000000044f5be <runtime.systemstack+126>  000000000042f340 <runtime.mstart+0>
000000000522fe58:  0000000000000000  0000000000000000
000000000522fe68:  0000000000000000  00000000005d855c
000000000522fe78:  0000000000000000  0000000000000000
000000000522fe88:  0000000000000000  0000000000000000
000000000522fe98:  0000000000000000  00000000028c67e0
000000000522fea8:  00000000005d84d0  0000000000000000
000000000522feb8:  0000000000000000  0000000000000000
000000000522fec8:  00007ffc9279a393
runtime: unknown pc 0x5dbe0f79
stack: frame={sp:0x522fe08, fp:0x0} stack=[0x5031ed0,0x522fed0)
000000000522fd08:  00007ffc924d01f8  000000000522fd30
000000000522fd18:  0000000000424262 <runtime.newAllocBits+50>  0000000000000200
000000000522fd28:  0000000010030050  0000000000000001
000000000522fd38:  0000000000412ff0 <runtime.heapBits.initSpan+256>  0000000000450ec0 <runtime.cgocallback_gofunc+0>
000000000522fd48:  0000000000000000  000000c042296000
000000000522fd58:  00007ffc924bbf2e  0000000000388000
000000000522fd68:  00000000054308c0  000000000522fdd0
000000000522fd78:  000000c000000000  0000000000000001
000000000522fd88:  0000000002859c38  0000000000450ec0 <runtime.cgocallback_gofunc+0>
000000000522fd98:  0000000000000000  0000000000000040
000000000522fda8:  00000000005d2e20  00000319000001c1
000000000522fdb8:  000000c0423ab6f0  000000c042056000
000000000522fdc8:  00000000005d7074  00000319000001c1
000000000522fdd8:  0000000000002000  0000000002858170
000000000522fde8:  000000c0423ab6e8  000000c0423ab6f0
000000000522fdf8:  000000c042056000  000000c0423ab6f0
000000000522fe08: <0000000000450e13 <runtime.asmcgocall+115>  0000000000000005
000000000522fe18:  000000c042056000  000000000522fe40
000000000522fe28:  000000000044c949 <runtime.(*mcache).nextFree.func1+57>  00000000001c0000
000000000522fe38:  0000000000000960  000000c042038000
000000000522fe48:  000000000044f5be <runtime.systemstack+126>  000000000042f340 <runtime.mstart+0>
000000000522fe58:  0000000000000000  0000000000000000
000000000522fe68:  0000000000000000  00000000005d855c
000000000522fe78:  0000000000000000  0000000000000000
000000000522fe88:  0000000000000000  0000000000000000
000000000522fe98:  0000000000000000  00000000028c67e0
000000000522fea8:  00000000005d84d0  0000000000000000
000000000522feb8:  0000000000000000  0000000000000000
000000000522fec8:  00007ffc9279a393

goroutine 1 [syscall]:
github.com/go-gl/gl/v4.1-core/gl._Cfunc_glowUseProgram(0x5dbe0f70, 0xc000000003)
        _cgo_gotypes.go:11709 +0x4c
github.com/go-gl/gl/v4.1-core/gl.UseProgram(0x3)
        C:/Users/janiv/go/src/github.com/go-gl/gl/v4.1-core/gl/package.go:7839 +0x3c
_/C_/Users/janiv/OneDrive/Code/GoTest/lib/graphics.SetProgram(0x3)
        C:/Users/janiv/OneDrive/Code/GoTest/lib/graphics/graphics.go:110 +0x30
main.main()
        C:/Users/janiv/OneDrive/Code/GoTest/main.go:226 +0x121c
rax     0x0
rbx     0xc0423ab720
rcx     0x3
rdi     0xc0423ab720
rsi     0xc042056000
rbp     0xc0423ab6d0
rsp     0x522fe08
r8      0xc042038000
r9      0x0
r10     0x0
r11     0x246
r12     0x40
r13     0x40
r14     0x0
r15     0x450ec0
rip     0x5dbe0f79
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b
exit status 2

It seems to me that it's caused by GC somehow, since it happens after some time. Any ideas what's up? Thanks!

Update: debug.SetGCPercent(-1) solves the issue, so GC seems to be the culprit...

dmitshur commented 6 years ago

Does this happen if you try running an example program?

If not, there's a possibility it's an issue with your code. I can't easily tell what it is just from the information you've provided.

janivanecky commented 6 years ago

Thanks for pointing out the example, I was able to run it without any issues, which lead me to finding out what's the cause - I was missing runtime.LockOSThread() call. Thanks again! Closing the issue.

dmitshur commented 6 years ago

Glad you figured it out. For reference, the note about having to use LockOSThread is mentioned in the last paragraph of https://github.com/go-gl/gl#usage.