How to check error in GLFW

To check for errors in GLFW, we register an error callback function with GLFW and it is called automatically when there is an error. This is a cleaner method than having to check explicitly for errors, like in OpenGL or GLEW.

This callback can be registered with GLFW even before GLFW has been initialized. This is useful because errors in initialization can also be caught.

The error values I found in GLFW are:

GLFW_NOT_INITIALIZED
GLFW_NO_CURRENT_CONTEXT
GLFW_INVALID_ENUM
GLFW_INVALID_VALUE
GLFW_OUT_OF_MEMORY
GLFW_API_UNAVAILABLE
GLFW_VERSION_UNAVAILABLE
GLFW_PLATFORM_ERROR
GLFW_FORMAT_UNAVAILABLE

A typical usage of GLFW with error callback:

void ErrorCallback(int, const char* err_str)
{
    std::cout << "GLFW Error: " << err_str << std::endl;
}

void SomeInitFunction()
{
    // Register error callback first
    glfwSetErrorCallback(ErrorCallback);

    // Start GLFW next
    const int ret = glfwInit();
    if (GL_FALSE == ret)
    {
        std::cout << "GLFW Error!n";
    }

    // Other GLFW functions go here ...
}

Tried with: GLFW 3.1.1 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s