go-gl / gl

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

Question: do really debug functions work? #116

Open hajimehoshi opened 6 years ago

hajimehoshi commented 6 years ago

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 https://github.com/go-gl/gl/issues/40 , and perhaps these functions don't work now?

dmitshur commented 6 years ago

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

pwaller commented 5 years ago

Further reference: https://github.com/go-gl/glow/issues/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 fromC.glowDebugMessageCallback`, or otherwise could we add a comment explaining its reason for existence?

errcw commented 5 years ago

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).