I'm coding a simulation program which displays the results in a window. The main thread handles the rendering while another thread handles the events. However the sf::Window function, global.app.WaitEvent() never returns, regardless of the event.
int main(){
global.app.Create(...);
sf::Thread thread(&getEvents);
thread.Launch();
while(not finished){
...
glBegin()/glEnd()
global.app.Display()
...
}
return;
}
void getEvents(){
sf::Event event;
while (global.app.WaitEvent(event)){
if (event.Type == sf::Event::Closed)
break;
}
}
I tried adding global.app.SetActive() and sf::Context con to getEvents(), but it doesn't work either.
Can anyone help me get this to work? Thanks in advance
Side note:
I do not need event handling for the window, but the window will hang if it loses focus, even though the program is still running fine. So I think I need to clear the event stack periodically. I don't think I can put event handling in the main thread's loop, since each iteration takes several seconds to complete (the long period will probably trigger the window hang also). Also, this is for Windows XP. When running on Windows 7, the window hang problem doesn't occur even without event handling coded in.