Page 1 of 1

[Solved]Quick SDL Question

Posted: Sat May 09, 2009 9:56 pm
by XianForce
Okay, I'm going through Lazy Foo's Tutorials, and in all of his tutorials he has this when he's handling events:

Code: Select all

//While the user hasn't quit

while( quit == false )
{
     //Handles events, etc.
}

My question: Is that really necessary? When the application is closed, wouldn't it stop running?

Re: Quick SDL Question

Posted: Sat May 09, 2009 10:52 pm
by MarauderIIC
In general, you want to manually clean things up. So if the user clicks "exit", you set quit to true and let it fall through so you can call SDL_Quit, etc. This way you can tell the difference between a clean exit and a not-clean exit.

Re: Quick SDL Question

Posted: Sat May 09, 2009 11:04 pm
by XianForce
MarauderIIC wrote:In general, you want to manually clean things up. So if the user clicks "exit", you set quit to true and let it fall through so you can call SDL_Quit, etc. This way you can tell the difference between a clean exit and a not-clean exit.
Oh. That makes complete sense now that you say it haha.

Re: [Solved]Quick SDL Question

Posted: Thu May 14, 2009 5:57 pm
by Ginto8
a somewhat easier thing to do this (no need to have an extra variable) would be:

Code: Select all

while(1)
{
    if([user quits])
        break;
}
just as a thought :)

Re: [Solved]Quick SDL Question

Posted: Thu May 14, 2009 5:58 pm
by XianForce
Yeah, that'd work well too :)

Re: [Solved]Quick SDL Question

Posted: Thu May 14, 2009 7:43 pm
by MarauderIIC
Ginto8 wrote:a somewhat easier thing to do this (no need to have an extra variable) would be:

Code: Select all

while(1)
{
    if([user quits])
        break;
}
just as a thought :)
This breaks structured programming rules (one entry, one exit), which you shouldn't just break all willy-nilly, but are rules that I regard as more breakable than other rules. Besides, [user quits] -- if that's not a variable somehow, why not just have while (![user quits]) ?