GLFW_NO_WINDOW_CONTEXT when changing resolution

Started by Danjb, March 16, 2019, 15:58:15

Previous topic - Next topic

Danjb

I am trying to support changing resolution on the fly. It works fine for me 95% of the time, but very occasionally the game crashes with the following error:

GLFW_NO_WINDOW_CONTEXT error
Description : Cannot swap buffers of a window that has no OpenGL or OpenGL ES context
Stacktrace : org.lwjgl.glfw.GLFW.glfwSwapBuffers(GLFW.java:4521)
...


This is significantly more common on less powerful systems; a friend of mine sees this crash consistently.

I haven't been able to find much information about this error and I have no idea what would cause it. I am specifically destroying the old window, creating a new one and setting the context, before I try to render:

GLFW.glfwDestroyWindow(window);
...
window = GLFW.glfwCreateWindow(...);
if (window == 0) {
    throw new RuntimeException("Failed to create window");
}
GLFW.glfwMakeContextCurrent(window);


Would you expect this to work, or am I missing something?

EDIT: glSwapBuffers is being called from the same thread, AFTER creating the new window, so I don't understand how this error could come about.

Thanks,
Danjb

spasi

This is the GLFW check that triggers the error you're seeing: window->context.client == GLFW_NO_API. I can't guess how that could happen without a code sample that reproduces the issue. You may also want to try LWJGLX/debug to verify that there aren't any obvious issues in your code.

In any case, there's a much better way to toggle fullscreen mode and/or change the resolution: glfwSetWindowMonitor. This function can do both changes without destroying the OpenGL context.

Danjb

You are a lifesaver! Thank you, that's much cleaner.

The only downside is that the window hints (in particular, the "decorated" flag) can only be set when the window is first created, but I can live with that.

I am still curious about that error. I don't have time right now to produce a self-contained sample, but I may be back.