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

Author Topic: Behaviour of the standard "input -> update -> render" after RenderWindow closing  (Read 1322 times)

0 Members and 1 Guest are viewing this topic.

Weby

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Hi !

In my projects, I tend to use the standard "ProcessInputs" -> "Update" -> "RenderFrame" loop.

Today however, I noticed that I usually drop a `renderWindow->close()` statement inside the "Update()" method, which is ran before the "RenderFrame()" method in every loop. In addition to that, I do not perform any check to see if the window is still open in the "RenderFrame()" method, simply assuming the window will be open.

...but it shouldn't be, and I almost never have issues with having a "RenderFrame()" called, that in turn calls `renderWindow->clear()`, `renderWindow->draw(...)`, and `renderWindow->display()` without checks.

How is that possible ? What does actually `renderWindow->close()` do ? Does it close instantly or does it wait for the next "clear/display" ?

Or perhaps do the "clear()" and "display()" methods check for the renderWindow's availability ?

Thanks for enlightnening me !

...And merry Christmas !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::RenderWindow is safe regarding its own internal state. So a closed window will not crash nor produce any undefined behavior, it will just do nothing.
Laurent Gomila - SFML developer

Weby

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Unless you call ->close() twice ? :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
No.
Laurent Gomila - SFML developer