https://bugs.winehq.org/show_bug.cgi?id=38402
Bug ID: 38402 Summary: glDebugMessageCallback is broken Product: Wine Version: unspecified Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: opengl Assignee: wine-bugs@winehq.org Reporter: chris.kcat@gmail.com Distribution: ---
According to the KHR_debug extension spec, the function glDebugMessageCallback takes a function pointer callback with the type:
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam);
https://www.opengl.org/registry/specs/KHR/debug.txt
In particular, it notes that the function callback uses the same calling convention as the other GL functions. The problem is that on Windows, GL uses the stdcall calling convention, while on Linux it uses cdecl. Wine's glDebugMessageCallback thunk passes the callback through as-is, so the system's libGL tries to call an stdcall function as though it was cdecl, causing it to crash upon returning.
Another problem is that the spec says:
"When DEBUG_OUTPUT_SYNCHRONOUS is disabled, the driver is optionally allowed to concurrently call the debug callback routine from potentially multiple threads, including threads that the context that generated the message is not currently bound to."
meaning the callback can be called on threads other than the one OpenGL is being used on. This is a problem because it may be called on one or more internal driver threads that were not created using the Windows API, and if the callback function tries to do anything that relies on Windows-related thread information, it won't be there.