Destroying window failure, glfwDestroyWindow doen't work

When I want to release context, I use glfwDestroyWindow (myWindow). This worked on my old computer, win10, nvidia 1080Ti. However, it didn’t work on my new notebook, win11, nvidia rtx 2050, visual studio 2022. I also tried to set window-close flag by calling glfwSetWindowShouldClose (myWindow, TRUE), but when I check the flag by calling BOOL temp = glfwWindowShouldClose (myWindow), I got a FALSE, which was quite unreasonable. Is it because my new notebook installed a win11 or nvidia rtx2050 ?

This sounds like a bug in GLFW. Do you have a minimal example program? Does this happen in the GLFW test or example programs?

Have you set an error callback that prints errors in GLFW?

I find the reason now. It’s the Nvidia GPU driver setting. On my old computer, I set the ‘thread optimization’ as ‘NO’, but on this new computer, I have to set it as ‘Auto’, otherwise, the render threads in my program will run in chaos.

That’s peculiar. What does that functionality do? I’m not sure if I understand how that can affect something like glfwWindowShouldClose returning GLFW_FALSE after doing glfwSetWindowShouldClose(..., GLFW_TRUE).

… well, unless you’re calling these from multiple threads, thereby not following the requirements of GLFW whatsoever.

Yes, I used glfw in a multithreading program

Are you using GLFW correctly? Mostly all of the GLFW calls you make must run on the main thread.

Is this relevant?

For each MFC thread (AfxBeginThread), I created a window and made it as a glfw context, then I rendered images (e.g., glClear, glfwSwapBuffers, …) in the context. After rendering, I released context for each thread and killed both threads.

GLFW windows can only be created from the main thread, see:

In particular the sentences:

The reference documentation for every GLFW function states whether it is limited to the main thread.

Initialization, termination, event processing and the creation and destruction of windows, cursors and OpenGL and OpenGL ES contexts are all restricted to the main thread due to limitations of one or several platforms.

You can create all the windows you need from the main thread, and then call glfwMakeContextCurrent to make the windows context current on the thread you want to draw to that window from.

Note that main thread here means the thread which your program was started with - i.e. the one where main() was called.

1 Like

Oh, I see. I’m so grateful for your reminding. Now I changed my codes as you suggested.