go-gl / gl

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

Error when calling GenVertexArrays() #82

Closed fanmanpro closed 7 years ago

fanmanpro commented 7 years ago

I've been using Go's go-gl package for quite a while now. Everything was working 100% until I did some refactoring and now I'm getting the stranges error:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw(0x65d0fe, 0x2a)
    /usr/lib/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
    /usr/lib/go/src/runtime/signal_unix.go:274 +0x2db
runtime.asmcgocall(0x8, 0x97ed40)
    /usr/lib/go/src/runtime/asm_amd64.s:633 +0x70

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x5b8ad0, 0xc420049c00, 0xc4200001a0)
    /usr/lib/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc420049bc0 sp=0xc420049b80
github.com/go-gl/gl/v4.5-core/gl._Cfunc_glowGenVertexArrays(0x0, 0xc400000001, 0xc42006c7d8)
    github.com/go-gl/gl/v4.5-core/gl/_obj/_cgo_gotypes.go:4805 +0x45 fp=0xc420049c00 sp=0xc420049bc0
github.com/go-gl/gl/v4.5-core/gl.GenVertexArrays(0x1, 0xc42006c7d8)

...

runtime.main()
    /usr/lib/go/src/runtime/proc.go:185 +0x20a fp=0xc420049fe0 sp=0xc420049f88
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420049fe8 sp=0xc420049fe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:2197 +0x1
exit status 2

shell returned 1

I've updated my drivers and a empty OpenGL scene works 100% without generating vertex arrays.

Here is my go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/<user>/Projects/<project>"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build983667275=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Thanks

dmitshur commented 7 years ago

Everything was working 100% until I did some refactoring and now I'm getting the stranges error

Does it still work if you go back to the version before the refactor?

If so, can you identify which (minimal) change it was that started causing this?

So far, this looks like you're doing something wrong in the user code.

fanmanpro commented 7 years ago

Thanks @shurcooL In terms of the user code it is fairly simple:

var vertexArrayID uint32
gl.GenVertexArrays(1, &vertexArrayID) // ERROR IS HERE
gl.BindVertexArray(vertexArrayID)

The above code didn't change after the refactoring and I can't think of anything in the code that could interfere with the first two lines.

However, I agree with you that it is likely not something in the go-gl package but how it is used. Is there perhaps a "checklist" of things to avoid to prevent memory errors?

dmitshur commented 7 years ago

Are you successfully creating an OpenGL context? Is it the right version?

The cube example does something very similar, does it work ok for you?

fanmanpro commented 7 years ago

Are you successfully creating an OpenGL context?

Nope, context was created only afterwards. What threw me off was that the empty scene still worked without having to create a OpenGL context. Thanks so much @shurcooL