Reputation: 135
I Initialize Glfw, create window and set scroll callback:
GLFWwindow * window = glfwCreateWindow (...);
glfwSetScrollCallback(window, GlScrollInput);
I have somewhere else function:
GlScrollInput (GLFWwindow * window, double x, double y){...}
Lets say after first usage I stored this pointer GLFWwindow * window. Is there a way to tell if this glfw window pointer is still valid(window is initialized and not destroyed or terminated)?
Upvotes: 0
Views: 260
Reputation: 9540
You need to keep track of that yourself. In general, it's impossible for any C++ framework to check whether a raw pointer is still valid.
If the memory a pointer points to is freed, accessing its contents is now undefined behaviour. Any value could be in that section of RAM, thus any check you do will give you a random answer at best or segfault at worst.
TL;DR when working with pointers in C++ it's your responsibility to track the lifetime of your objects.
When a window in GLFW is destroyed, its contents will be freed, thus running into the above scenario.
Upvotes: 1