GLFW: window & contextGLFW 3.3

glfwGetError

Returns the last GLFW error on this thread (and its message), then clears it.

Signature

int glfwGetError(const char** description);

How it works

An alternative to the error callback when you want to check one specific call: call the function, then ask glfwGetError whether it failed.

It returns GLFW_NO_ERROR (0) when nothing went wrong since the last check. Reading the error clears it, so a second call right after returns GLFW_NO_ERROR.

Parameters

descriptionconst char**

Where to store a pointer to the message, or NULL if you only want the code. Set to NULL when there is no error.

Return value

The error code (e.g. GLFW_VERSION_UNAVAILABLE), or GLFW_NO_ERROR.

Tips & pitfalls

Example

example.cpp
1GLFWwindow* window = glfwCreateWindow(800, 600, "App", nullptr, nullptr);
2if (!window) {
3    const char* why = nullptr;
4    int code = glfwGetError(&why);
5    std::fprintf(stderr, "window failed (0x%X): %s\n", code, why ? why : "?");
6}
Official GLFW documentation