SFML community forums

Help => System => Topic started by: RedTheGreen on January 08, 2013, 06:47:03 am

Title: [2.0] sf::Thread and sf::RenderWindow::pollEvent()
Post by: RedTheGreen on January 08, 2013, 06:47:03 am
Is it possible to utilize a thread mainly for handling the close button of the application window? My current code doesn't seem to work. The window just freezes as if I wasn't checking for events, although the thread is running.

#include <SFML/Graphics.hpp>
//#include <game.hpp>

sf::RenderWindow appWindow( sf::VideoMode( 800,600 ),"Fox" );

void AppEvents()
{
    while( appWindow.isOpen() )
    {
        sf::Event event;
        while( appWindow.pollEvent( event ) )
        {
            if ( event.type == sf::Event::Closed )
                appWindow.close();
        }
    }
}

int main(int argc, char* argv[])
{
    //Player player;
    //Room room("res/rooms/MainMenu/room.xml");
    sf::Thread appEvents(&AppEvents);
    appEvents.launch();
    appEvents.wait();
    return EXIT_SUCCESS;
}

Any body have an idea why that might be?
Title: Re: [2.0] sf::Thread and sf::RenderWindow::pollEvent()
Post by: Laurent on January 08, 2013, 08:03:33 am
Read the tutorial about windows, it's clearly explained.
Title: Re: [2.0] sf::Thread and sf::RenderWindow::pollEvent()
Post by: RedTheGreen on January 10, 2013, 04:07:15 am
Thanks.