SFML community forums
Help => Window => Topic started by: tymofey on September 19, 2011, 07:51:15 pm
-
I have a thread one where i create the window:
sf::Window* wnd = new sf::Window(sf::VideoMode(400, 300), "some title", sf::Style::Close);
Then i pass the wnd ponter to two other threads.
In thread two i query window for events:sf::Event event;
while (true)
while(wnd->PollEvent(event))
{
//....
}
And in thread three I draw in it:while (true)
{
//...
wnd->Display();
}
The window is of course protected by proper locking.
This causes lots ofFailed to activate window's context
messages to the console. Is what i am trying to do even possible?
-
You must first deactivate (SetActive(false)) the window in the thread where it is active (->the thread where you created it), before activating it in another thread.
-
Would doing that really often (like every frame) introduce huge overhead?
-
Yes. But why would you need to draw to the same window from multiple threads?
-
i dont. i want to draw in one thread and poll events in another. but it appears that i still need the window to be active to poll events from it.
-
Nop. SetActive activates the OpenGL context, which is necessary only for drawing operations.
-
then appearently i am doing something really wrong as the window does not seem to generate any events this way
-
Some OSes (like Windows) require events to be polled from the thread that created the window.
-
thanks, that explains everything. i believe this should be mentioned in the docs.
-
i believe this should be mentioned in the docs
I agree ;)