2
\$\begingroup\$

For some reason after calling 'glfwCreateWindow' I get back NULL as the return value. I'm initializing GLFW beforehand with 'glfwInit' and while searching for a solution tried setting 'glfwSetErrorCallback' to print if there is an error but it doesn't call my function after returning NULL.

I'm using GLFW 3 with C++ on Visual Studio 2010 x64.

\$\endgroup\$
7
\$\begingroup\$

You can see from the source code that glfwCreateWindow returns a null pointer in only a few circumstances (as of this writing).

  • GLFW is not initialized at all (_GLFW_REQUIRE_INIT_OR_RETURN(NULL); on line 137).
  • The width or height you specify for the window is zero or negative.
  • The context configuration (controlled by you via the window hints, checked via _glfwIsValidContextConfig on line 184) is invalid.
  • Platform-level window creation fails (_glfwPlatformCreateWindow on line 216).
  • Refreshing the GL context to get the actual requested context attributes fails (_glfwRefreshContextAttribs on line 226).
  • The refreshed context doesn't match the requested context properties (_glfwIsValidContext on line 234).

Since you don't get an error handler callback invoked, you can probably discard the second reason (it's the only one that might fire an error handler call, and it should be pretty easy to verify on your end anyway).

This means the likely options are that you didn't initialize GLFW correctly or correctly check the return value of the initialization (you don't provide your source, so it's impossible to say) or your ask for invalid context options via the window hints system.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.