Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [2.0] sf::Thread and sf::RenderWindow::pollEvent()  (Read 3674 times)

0 Members and 1 Guest are viewing this topic.

RedTheGreen

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • RedTheGreen's Website
    • Email
[2.0] sf::Thread and sf::RenderWindow::pollEvent()
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [2.0] sf::Thread and sf::RenderWindow::pollEvent()
« Reply #1 on: January 08, 2013, 08:03:33 am »
Read the tutorial about windows, it's clearly explained.
Laurent Gomila - SFML developer

RedTheGreen

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • RedTheGreen's Website
    • Email
Re: [2.0] sf::Thread and sf::RenderWindow::pollEvent()
« Reply #2 on: January 10, 2013, 04:07:15 am »
Thanks.