glDebugMessageCallbackARB INVALID_OPERATION

This is the first time I try to manually load an OpenGL extension so this could be a very simple error.

I am trying to get glDebugMessageCallbackARB to call a custom function I am providing using gl3w. This is the code I am trying to make work:


typedef GLvoid (APIENTRY *GLDEBUGPROCARB)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam);
typedef GLvoid (APIENTRYP DebugMessageCallbackARBPROC )(GLDEBUGPROCARB callback, GLvoid* userParam);


GLvoid APIENTRY GLMessageHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) { 
   //Do nothing for now.
}

bool initializeOpenGLDebugOutput() {
    DebugMessageCallbackARBPROC glDebugMessageCallback = (DebugMessageCallbackARBPROC)gl3wGetProcAddress("glDebugMessageCallbackARB");

    if ( (glDebugMessageCallback == NULL) )
    	return false;

    void* DebugMessageCallBackLocation = (void*)glDebugMessageCallback;
    void* GLMessageHandlerLocation     = (void*)&GLMessageHandler;
    LOG_DEBUG_VARIABLE("OpenGL",DebugMessageCallBackLocation);
    LOG_DEBUG_VARIABLE("OpenGL",GLMessageHandlerLocation);
    glDebugMessageCallback(&GLMessageHandler,0);

    {
		std::string error = getGLErrorString();
		if (error.size()!=0) {
			LOG_ERROR("OpenGL",translate("Error initializing OpenGL Debug Message System."));
			LOG_ERROR("OpenGL",error);
			return false;
		}
    }
    LOG_INFO("OpenGL","OpenGL Debug Message System initialized.");
    return true;
};


And this is the output I am getting:


DEBUG  (OpenGL): DebugMessageCallBackLocation = 0x6a216c40
DEBUG  (OpenGL): GLMessageHandlerLocation = 0x437568
ERROR  (OpenGL): Error initializing OpenGL Debug Message System.
ERROR  (OpenGL): GL_INVALID_OPERATION

I read http://www.opengl.org/registry/specs/ARB/debug_output.txt and could not find any references to INVALID_OPERATION and the function I am using.

I am not sure if it matters, but are you setting the debug flag in the OpenGL context? I use glfw, with the following:

	glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);

before calling glfwOpenWindow().

I also do the following, to support AMD specifically:

		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
		if (glDebugMessageCallbackARB != 0)
			glDebugMessageCallbackARB(DebugFunc, (void*)15);
		else if (glDebugMessageCallbackAMD != 0)
			glDebugMessageCallbackAMD(DebugFuncAMD, (void*)15);

These callbacks use a little different signatures. A little embarrassing, but I don’t remember what the number 15 is for. I probably copied this from somewhere else.

I’ve never had to do that AMD switch of yours, and I’ve been using ARB_debug_output for about 9 months now (on Windows).

Running Windows, with the following stats:

GLFW Version: 2.7.2
Vendor: ATI Technologies Inc.
Renderer: AMD Radeon HD 6570
Version: 4.0.10243 Compatibility Profile Context
GLSL: 4.00
OpenGL context version parsed by GLFW: 4.0.10243
OpenGL context flags: none
OpenGL profile mask: 0x00000002 (compatibility)

glDebugMessageCallbackARB is not defined, but glDebugMessageCallbackAMD is (using GLEW). I think I have the same result running Ubuntu on the same machine. Testing on other machines, I get the glDebugMessageCallbackARB working.

If I understood that correctly the 15 is a user provided pointer to anything you want that is passed to your callback. I still couldn’t get it working.

I am using SFML and not glfw, I will look on how to pass the debug flag to the window.

By the way these are my GL_VERSION and GL_SHADING_VERSION:



2012-Feb-15 21:31:56:   INFO  (SFMLEngine): Setting Video Mode to 800x600x32.
2012-Feb-15 21:31:57:   INFO  (SFMLEngine): OpenGL 4.2.11318 Compatibility Profile Context GLSL 4.20 initialized.

glDebugMessageCallbackARB is not defined, but glDebugMessageCallbackAMD is (using GLEW).

Of course it’s not defined. Your GL version is 4.0. AMD doesn’t ship 4.0 drivers anymore; any hardware that could run 4.0 will run 4.1 and 4.2 just fine. This means your drivers are from before AMD started shipping 4.1 drivers. Which likely means it was from before AMD started shipping ARB_debug_output.

Update your drivers and you’ll probably be fine.

I updated to the latest drivers.

GLFW Version: 2.7.2
Vendor: ATI Technologies Inc.
Renderer: AMD Radeon HD 6570
Version: 4.2.11399 Compatibility Profile Context
GLSL: 4.20
OpenGL context version parsed by GLFW: 4.2.11399
OpenGL context flags: none
OpenGL profile mask: 0x00000002 (compatibility)

But glDebugMessageCallbackARB is still not defined. And now, calling glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) no longer works, it will crash (segmentation fault in C:\Windows\SysWOW64\atioglxx.dll).

Are you creating a debug context? You need to call glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); before opening the window.

I am using a library to create the context: SFML. So far I haven’t found a way to pass parameters to the context creation routines.

I am planing to drop the dependencies from it and move to a less “intrusive” library in the future.

I just find odd that the GL_ENABLE throw the INVALID_OPERATION when the context is not in DEBUG mode. It makes sense to do that but I have not found a reference for this behaviour on the spec: http://www.opengl.org/registry/specs/ARB/debug_output.txt

As noted above, I use glfw. I like it, as it has a minimal impact. The only purpose is to provide a multi-platform library for opening a window, creating an OpenGL context and managing input. Even such a thing as the main event loop is left to you, with helpful functions to make it easy.