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

Author Topic: SFML 2.0 sf::RenderWindow freeze when Control-C pressed  (Read 2451 times)

0 Members and 2 Guests are viewing this topic.

GAFBlizzard

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML 2.0 sf::RenderWindow freeze when Control-C pressed
« on: February 16, 2012, 08:47:17 am »
Hello,

I am using a recent build (LaurentGomila-SFML-e7256e3) of SFML 2.0.  I have an application configured to use the Windows console subsystem (running under Windows 7), and this allows me to print debug information to the console.

If I have a window open in even a simple application loop that includes window.Display(), the Display() call seems to freeze forever if I press Control-C in the console window.  The window closes, but the Display() call is frozen so the application does not exit.  I can post code if needed, but it should happen with any such test program.

Could this be due to a strange sleep value due to Display() attempting to maintain the frame rate after the window is closed?

Thanks very much for your time!

GAFBlizzard

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML 2.0 sf::RenderWindow freeze when Control-C pressed
« Reply #1 on: February 16, 2012, 09:25:29 am »
The problem appears to be that SwapBuffers hangs internally (calledby SFML).  My workaround is to manually set a Control-C/Control-Break handler using SetConsoleCtrlHandler (http://msdn.microsoft.com/en-us/library/ms686016).  I would presumably use sigaction with SIGINT and SIGTERM under Linux/Mac.

At any rate, in the control handler, I changed some engine state so that my game loop would end itself cleanly.  If I am not mistaken, merely shutting down my engine (and presumably SFML in the process) in the control handler caused a crash because my main thread would still potentially be in the middle of rendering and/or using engine data structures.

I think this solution is acceptable, but if anyone familiar with SFML has additional comments about console Control-C handling while SFML window code is running, please feel free to share.  :)

 

anything