go-gl/gl

Question: do really debug functions work?

hajimehoshi opened this issue · 3 comments

For example, in the current DebugMessageCallback implementation, Go function's pointer is converted to a C pointer:

func DebugMessageCallback(callback DebugProc, userParam unsafe.Pointer) {
	userDebugCallback = callback
	C.glowDebugMessageCallback(gpDebugMessageCallback, (C.GLDEBUGPROC)(unsafe.Pointer(&callback)), userParam)
}

I was wondering if this really works, and anyone tests this. I found #40 , and perhaps these functions don't work now?

I have never used any of the *Debug* functions in gl, so I can't say.

Further reference: go-gl/glow#3

It does look strange, but I believe can work. If you dig into it, you find that glowDebugMessageCallback ignores its callback parameter.

I don't know why there is a callback parameter. One thought I had was that it could be to prevent garbage collection of the function value, but I guess that doesn't make sense because the function value is stored in userDebugCallback.

@errcw could you shed light on the callback parameter? Could it be eliminated from C.glowDebugMessageCallback`, or otherwise could we add a comment explaining its reason for existence?

errcw commented

If I remember correctly it's simply an artifact of the code generation, i.e., it just takes the C definition so ends up with an extraneous parameter that is dropped so the C/Go machinery works. It would be a reasonable enhancement to add a comment or, even better, remove the unused parameter entirely (though if it involves too much special casing I'd be wary).