Brief summary: glClear(0) and glfwSetWindowMonitor() running on different threads causes segfault
If expected, it should be noted in the documentation at https://www.glfw.org/docs/latest/intro_guide.html#thread_safety. If this isn’t expected behavior, I can provide a testcase, although it will take a few days.
I separated event handling and rendering into two threads.
In event handling: I set F11 in the key callback to switch between fullscreen and windowed mode.
In rendering: while(1) glClear(0);
When running my application: I press F11 to change from fullscreen to windowed mode. For event handling, mouse events land on applications as if the application was windowed, and the mouse cursor changes to a text cursor if the other application has text there. Rendering continues to fill the full screen. After the first switch consistently fails, F11 sometimes switches between windowed mode and fullscreen properly, and sometimes doesn’t. A few F11s later and the application will segfault on glClear(0).
glfwWindowHint(GLFW_DOUBLEBUFFER, 0) eliminates this problem, and F11 switches perfectly.
Sleeping for 100 ms between each glClear(0) significantly mitigates this problem. This shows that it’s glClear(0) and glfwSetWindowMonitor() running simultaneously that causes the problem.
Rendering things does not exhibit this problem as long as glClear(0) is not called. Everything is rendered properly.
Running input and rendering on the same thread, instead of two separate threads, eliminates the problem.
Intel HD4000, glad, mingw-w64