Programming => Lightweight Java Gaming Library => Topic started by: Danjb on March 16, 2019, 15:58:15

Title: GLFW_NO_WINDOW_CONTEXT when changing resolution
Post by: Danjb on March 16, 2019, 15:58:15
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:

Code: [Select]
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:

Code: [Select]
window = GLFW.glfwCreateWindow(...);
if (window == 0) {
    throw new RuntimeException("Failed to create 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.

Title: Re: GLFW_NO_WINDOW_CONTEXT when changing resolution
Post by: spasi on March 16, 2019, 18:27:18
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 (https://github.com/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.
Title: Re: GLFW_NO_WINDOW_CONTEXT when changing resolution
Post by: Danjb on March 18, 2019, 21:18:25
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.