Does anyone know under what circumstances will glfwPollEvents() automatically set the close flag that causes GLFW to close the window?
For learning purpose, currently my program contains both DirectX11’s code (using Win32 API directly) and OpenGL’s code (using GLFW). The window creation and main loop for each API are in separate functions. When you select another API from the UI inside the program, it will cause the function to return to the main function, which will destroy the current window and release all resource (since they are local variables), and call another function to create a new window and a main loop. Switching from GLFW to Win32 has no problem at all, but when switching from Win32 to GLFW, despite that GLFW window can be created without any problem and error, the main loop will execute only once, then it will automatically close afterwards. Both glError() and glfwGetError() return no errors at all.
After debugging I found that glfwPollEvents() somehow sets the close flag, which causes glfwWindowShouldClose() to return true and end the main loop. If I comment out glfwPollEvents(), OpenGL will render without any problem, but of course there won’t be any event polling. I tried setting up WindowCloseCallback, and right after the program executes glfwPollEvents(), the callback is called, so clearly either glfwPollEvents() sets the close flag, or the flag is set elsewhere. The problem is KeyCallback is never called and I didn’t call glfwSetWindowShouldClose() anywhere in the code, so I don’t know why the close flag is set.
Does anyone know why this happened? Thanks.