Hello Guest

GLFW_NO_WINDOW_CONTEXT when changing resolution

  • 2 Replies
  • 220 Views
*

Offline Danjb

  • *
  • 10
GLFW_NO_WINDOW_CONTEXT when changing resolution
« 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]
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:

Code: [Select]
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
« Last Edit: March 16, 2019, 16:10:21 by Danjb »

*

Offline spasi

  • *****
  • 2128
    • WebHotelier
Re: GLFW_NO_WINDOW_CONTEXT when changing resolution
« Reply #1 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 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.

*

Offline Danjb

  • *
  • 10
Re: GLFW_NO_WINDOW_CONTEXT when changing resolution
« Reply #2 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.