Hi, my question is this: Is it safe to send OpenGL commands when a window has been set as the active window, then closed?
Hopefully that is a yes or no question. If not, here is a more detailed description of my problem.
I have been using OpenGL with SFML for some time now. I am running Windows 7 Ultimate, with SFML 2.0, with static linking. This problem occurs both when I create a context with OpenGL 3.3 and 4.1.
In my main loop, the window polls for input, does its OpenGL commands, then calls Display() on the active window. If during the polling for events, sf::Event::Closed is detected, Close() is called active window immediately.
What this means is that for at least one iteration of the main loop, OpenGL commands are being sent despite the active window being closed.
It looks something like this:
sf::Window window(sf::VideoMode(800, 600), "SFML window");
//initialize OpenGL (set up shaders, etc.)
while (window.isOpen())
{
sf::Event anEvent;
while (window.PollEvent(anEvent))
{
if (anEvent.Type == sf::Event::Closed)
window.Close();
}
//OpenGL commands...
window.Display();
}
After the window is closed, the main loop exits, and the program quits.
This works fine, but I made some additions to my OpenGL code to use Vertex Array Objects and Depth Buffering, without changing any SFML-related code and now when I close the window, instead of exiting smoothly, the program crashes. Debugging this shows that sending a draw command then modifying a uniform variable causes the program to crash. This is kind of unusual, since OpenGL commands themselves do not generally cause a program to crash.
To workaround this I have had to modify the main loop a little bit.
while (window.isOpen())
{
sf::Event anEvent;
bool isOpen = true;
while (window.PollEvent(anEvent))
{
if (anEvent.Type == sf::Event::Closed)
isOpen = false;
}
//OpenGL commands...
window.Display();
if (!isOpen)
window.Close();
}
Now, OpenGL commands are never being sent to a closed window.