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

Author Topic: RenderWindow inexplicably hangs on close  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
RenderWindow inexplicably hangs on close
« 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):
  • Code::Blocks
  • Win7
« Last Edit: September 08, 2014, 01:01:40 am by Conduit »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: RenderWindow inexplicably hangs on close
« Reply #1 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 )
« Last Edit: September 08, 2014, 01:25:08 am by G. »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: RenderWindow inexplicably hangs on close
« Reply #2 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
« Last Edit: September 08, 2014, 01:21:13 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: RenderWindow inexplicably hangs on close
« Reply #3 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!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: RenderWindow inexplicably hangs on close
« Reply #4 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.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: RenderWindow inexplicably hangs on close
« Reply #5 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.