Skip to content

glfwMakeContextCurrent(nullptr) emits an error instead of detaching context #24

@mrizaln

Description

@mrizaln

As per the documentation, passing in NULL (or nullptr) into glfwMakeContextCurrent should detach the context from calling thread. This library instead emits an error into error callback with an error code GLFW_INVALID_VALUE and a message "window parameter invalid".

This code, for example, doesn't produce the same result compared to with original implementation:

glfwInit();
auto window = glfwCreateWindow(800, 600, "hello glfw", nullptr, nullptr);
glfwMakeContextCurrent(window);

// ...

auto current = glfwGetCurrentContext();
assert(current == window);                // ok in both

// ...

glfwMakeContextCurrent(nullptr);
current = glfwGetCurrentContext();
assert(current == nullptr);               // fail in emscripten-glfw; the current context unchanged

I traced the problem to this code, where iWindow with nullptr value is not handled differently and is passed directly to getWindow which then reports an error:

void Context::makeContextCurrent(GLFWwindow *iWindow)
{
auto window = getWindow(iWindow);
if(window)
{
fCurrentWindow = window;
fCurrentWindowOpaquePtr = iWindow;
fCurrentWindow->makeGLContextCurrent();
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions