SFML community forums

Help => General => Topic started by: Conduit on September 08, 2014, 12:57:56 am

Title: RenderWindow inexplicably hangs on close
Post by: Conduit on September 08, 2014, 12:57:56 am
Hello folks -

I've been working with SFML for a little over a month now, and have recently run into a bizarre issue that might be the result of a bug in the SFML library. I have a test program with a "main" function as follows:

int main()
{
    try
    {
        Foo foo("Foo!");
        CommandProcessor bar;
        sf::RenderWindow window(sf::VideoMode(640, 480), "Test", sf::Style::Close);

        while(window.isOpen())
        {
            sf::Event event;
            while(window.pollEvent(event))
            {
                bar.processEvent(event);
                if(event.type == sf::Event::Closed)
                {
                    std::cout << "preparing to close" << std::endl;
                    window.close();
                    std::cout << "close requested" << std::endl;
                }
            }
        }
    }
    catch(std::exception& e)
    {
        std::cout << "Unhandled exception - terminating program" << std::endl;
        std::cout << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

When I close the window via the button on the top right, I get the following text in the console:
Quote
preparing to close
close requested
after which the program hangs and I get the typical Windows "Program has stopped working [close button]" popup. Given the text in the console I have no idea how this could be happening unless, for some reason, the RenderWindow's close function is bugged. Is anyone able to offer advice? Thanks!

Environment (more added by request):
Title: Re: RenderWindow inexplicably hangs on close
Post by: G. on September 08, 2014, 01:17:25 am
I think a RenderWindow is supposed to .display() sometimes in order to correctly work.
You're right zsb, I'm mistaken, I think I mixed something in my head...  ???
(and I believe you of course! :D )
Title: Re: RenderWindow inexplicably hangs on close
Post by: zsbzsb on September 08, 2014, 01:17:43 am
If this is any issue with SFML then why do you still have your own objects in your code? Remove those and see if the issue goes away.

I think a RenderWindow is supposed to .display() sometimes in order to correctly work.

Huh?? Where did you here that? The display() function has nothing to do with managing the window. And if you don't believe me, check the implementation.

https://github.com/SFML/SFML/blob/master/src/SFML/Window/Window.cpp#L340
Title: Re: RenderWindow inexplicably hangs on close
Post by: Conduit on September 08, 2014, 02:02:38 am
Good call zsbzsb. I'd (stupidly) forgotten that there would be one last thing called before the program terminated - the destructors for my created objects. Had a typo in an iterator loop used to clean up a std::map. Thanks!
Title: Re: RenderWindow inexplicably hangs on close
Post by: zsbzsb on September 08, 2014, 02:11:38 am
Glad to help, just next time if you think SFML has an issue write and test a pure SFML example (none of your own code) to ensure the problem is really with SFML.  ;)
Title: Re: RenderWindow inexplicably hangs on close
Post by: Conduit on September 08, 2014, 07:26:16 am
Will do. Will probably be more careful about proper choice of prefix and postfix incrementation, too, hah.