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

Author Topic: Weird troubles when doing a loop inside main loop  (Read 2748 times)

0 Members and 1 Guest are viewing this topic.

LGV

  • Newbie
  • *
  • Posts: 11
    • MSN Messenger - laureano_river@hotmail.com
    • View Profile
Weird troubles when doing a loop inside main loop
« on: August 29, 2009, 04:14:29 am »
Hi, I have a problem that it's driving me crazy and I can't figure out how to avoid it. I was trying to this (App is a sf::RenderWindow, like in the tutorial "Using rendering windows")

Code: [Select]

while(App.IsOpened())
{
        for(;;)
        {
             if(App.GetInput().IsKeyDown(sf::Key::Escape) break;
             App.Clear(sf::Color(192, 192, 192));
        }

        // LOTS OF USEFUL CODE...

}

Well, this simple code, just doesn't work. I get no grey window (RGB 192,192,192 is grey), I can't get input so I can't "break" the loop. Worse, my entire machine gets really lag and almost lock up (!!). I just can't understand what I'm doing wrong. Any suggestions? I'm developing under Windows XP SP3 with Visual Studio 2008.
P.S: I was trying to do that because I'm doing a very simple menu for my game, so I need to get the game started when the user click on a button (I've already implemented this stuff and it works ok), but, until that, I have to show a menu or a picture so that is why I'm using a for( ;; ).

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Weird troubles when doing a loop inside main loop
« Reply #1 on: August 29, 2009, 04:57:08 am »
for( ;; ) is your problem IMO.

There is no Display in this loop.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Weird troubles when doing a loop inside main loop
« Reply #2 on: August 29, 2009, 10:27:50 am »
A call to App.Display is required to get things displayed on screen.
A call to App.GetEvent is required to get sf::Input updated.

Conclusion: never create nested endless loops into your main loop, so that you don't break the main execution flow. Keep a unique skeleton and adapt what is updated / displayed using the current state of the application.
Laurent Gomila - SFML developer

LGV

  • Newbie
  • *
  • Posts: 11
    • MSN Messenger - laureano_river@hotmail.com
    • View Profile
Weird troubles when doing a loop inside main loop
« Reply #3 on: August 31, 2009, 08:07:29 pm »
So after all the troubles were caused by my ugly endless loop  :oops:  :lol:. I'll try to do what you said Laurent, thx!!
EDIT: I did it!! I did it!! Now I've a nice menu without an ugly and dirty endless loop  8). Thx!