chsc/gogl

GetError() causes nil func value runtime error.

nergdron opened this issue · 2 comments

I'm writing a wrapper lib around gogl to make writing GL code in Go a little easier to deal with. One of them is a wrapper to turn the OpenGL error stack into a Go error:

func GLErrors() error {
errormsg := ""
for errcode := gl.GetError(); errcode != gl.NO_ERROR; errcode = gl.GetError() {
switch errcode {
case gl.INVALID_ENUM:
errormsg = errormsg + "GL_INVALID_ENUM "
case gl.INVALID_VALUE:
errormsg = errormsg + "GL_INVALID_VALUE "
case gl.INVALID_INDEX:
errormsg = errormsg + "GL_INVALID_INDEX "
case gl.INVALID_OPERATION:
errormsg = errormsg + "GL_INVALID_OPERATION "
case gl.INVALID_FRAMEBUFFER_OPERATION:
errormsg = errormsg + "GL_INVALID_FRAMEBUFFER_OPERATION "
case gl.OUT_OF_MEMORY:
errormsg = errormsg + "GL_OUT_OF_MEMORY "
default:
errormsg = errormsg + "GL_UNKNOWN_ERROR(" + string(errcode) + ")"
}
}
if len(errormsg) > 0 {
return errors.New(errormsg)
}
return nil
}

However, on a freshly installed gl33 from your repo, I get the following runtime error when calling it:

panic: runtime error: call of nil func value
[signal 0xb code=0x1 addr=0x0 pc=0x0]

goroutine 1 [syscall]:
github.com/chsc/gogl/gl33._Cfunc_goglGetError(0x100, 0x420a63)
/tmp/go-build389262905/github.com/chsc/gogl/gl33/_obj/_cgo_defun.c:234 +0x2f
github.com/chsc/gogl/gl33.GetError(0x700407306, 0x407b74)
/tmp/go-build389262905/github.com/chsc/gogl/gl33/_obj/gl33.cgo1.go:3584 +0x1c
github.com/unit3/violet.GLErrors(0x407306, 0x7f7e26f91030)
/home/graeme/code/go/src/github.com/unit3/violet/utils.go:17 +0x3b

Seems to indicate that the go gl33 lib doesn't actually point to a function for gl.GetError(). I'm on Ubuntu 12.04/x64, with latest NVidia binary drivers (v302).

chsc commented

Have you initialized gogl with gl.Init() first?

Ahhh I had, but this chunk of code that was erroring was getting called first. Thanks, not a bug. :)