This is some of the strangest behavior I've ever seen and I have no answer from myself.
I tried -fno-delete-null-pointer-checks while compiling both my game and engine and still the same behavior was observed as follows:
So I'm working on a window manager to deal with multiple windows in an application and everything is working fine but when I delete a window and keep the app running still with the other window I receive "GLFW Error 65544, WGL: Failed to make context current: The handle is invalid." and "GLFW Error 65544, WGL: Failed to make context current: The requested transformation operation is not supported.". Ok so I thought maybe I'm still setting window context to the now deleted pointer so I log a check in the following for loop that tests if the window == NULL which I set it too after freeing the window:
void windowmanagerUpdate(WindowManager *manager)
{
windowSystemPollEvents();
for(int i = 0; i < array_length(manager->window_cache); i++)
{
Window *w = manager->window_cache[i].window;
if(w)
{
//log_info("index: %i", i); - Check that stops error
windowSetContextCurrent(w);
windowUpdate(w);
}
}
}
After adding the one log to the statement just magically no more WGL errors, so what's going on this is so strange to me and as I said before explicitly telling gcc not to delete null pointer checks does not work either so maybe some people can shed some light on this issue.
Edit: sorry for not putting more info
So the Window type is just an abstracted window and under it is a WindowsWindow. windowSystemPollEvents just call glfwPollEvents(); windowSetContextCurrent(w) just calls glfwSetWindowCurrent(((WindowsWindow *)w)->native_window); windowUpdate(w) just calls glfwSwapBuffers(((WindowsWindow *)window)->native_window); and array_length just returns the length member of the dynamic array.
The manager is held in the applications data and doesn't change upon being created so it always points to the same address.
manager->window_cache[i].windowis not actuallynullwhenif (w)executes. Does it fail if compiled in debug mode? Also try putting a log output in theelsepath.managerpoints at the wrong data when entering the function and/orarray_lengthgives something out of bounds. And when you add an unrelated function call you scramble around the stack layout a bit so you hide the bug - you haven't fixed the bug. You'll need to carefully watchmanagerand every member of that one in your debugger. Because this bug really screams pointer to invalid data.