glDebugMessageCallback causes segfault

Viewed 2055

I'm in a bit of a catch-22 here. I can't debug my C++ OpenGL program because activating debug messages causes a segfault.

I have a debug callback function I register:

static void APIENTRY openglCallbackFunction(
  GLenum source,
  GLenum type,
  GLuint id,
  GLenum severity,
  GLsizei length,
  const GLchar* message,
  const void* userParam) {
  (void)source; (void)type; (void)id;
  (void)severity; (void)length; (void)userParam;
  fprintf(stderr, "%s\n", message);
  if (severity==GL_DEBUG_SEVERITY_HIGH) {
    fprintf(stderr, "Aborting...\n");
    abort();
  }
}

And I initiate the debug context in the following code:

this->window = glfwCreateWindow(this->winx, this->winy, "Cortex Stretcher", NULL, NULL);
  if(this->window == NULL) {
    fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
    glfwTerminate();
    return -1;
  }
  glfwMakeContextCurrent(this->window);

  GLint flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
  if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
  {
     cout << "Debug output enabled!" << endl;
     glEnable(GL_DEBUG_OUTPUT);
     glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
     glDebugMessageCallback(openglCallbackFunction, nullptr);
    //  glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
  }

If I merely comment out glDebugMessageCallback(openglCallbackFunction, nullptr); then my code runs without any errors (aside from my model rendering incorrectly which is why I'm trying to debug).

But if I try to register the callback, then my code segfaults (at registration). Any idea why? This is essentially just copy-pasted code.

Note: glGetString(GL_VERSION) returns 4.5.0 NVIDIA 375.39

1 Answers
Related