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.
FINAL EDIT AND ANSWER I PROMISE: Im on my laptop so it was using my integrated intel driver and so I forced it to use my Nvidia GPU: __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; AMD: __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; And BOOM, all errors magically disappeared so theirs not much you can really do about it. Maybe theirs a driver to fix this but I could care less.
Still getting my understanding of pointers down and I thought that If you assign anything to a pointer it will change it everywhere but no not if you pass a pointer that is a local pointer then it acts like pass by value kind of (Horrible description)
Basically :
I changed my remove cached window to this when before the free and NULL set were happening in the window destroy which would pass the window * but would be local and only change in the context of the function
void windowmanagerRemoveCachedWindow(WindowManager *manager, const uint32_t index)
{
log_info("Removing window at index %u from Window Manager", index);
windowDestroy(manager->window_cache[index].window);
array_append(manager->removed_indexes, index);
free(manager->window_cache[index].window);
manager->window_cache[index].window = NULL;
}