Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Event Handling

Started by nyl2000 May 10, 2012 at 2:46 AM 1 replies 1.3k views
Original Post
nyl2000
nyl2000
I am currently starting out with event handling systems in SDL/C++. I have followed a tutorial to create a simple program that should quit the program when the user X's out/Closes the window.

The program compiles and works as intended, except that the close button does not respond at all when it is clicked. The program stays in its while loop forever, without receiving the command to quit.

I am using a Windows7 Computer, with Codeblocks IDE.
Attached is the program, I am not sure what is preventing me from closing the window at all.
Oberon_Command
Oberon_Command


if(event.type == SDL_QUIT)
{//SDL_QUIT event type = Closing (Xing Out) Window
quit == true;
}


Should that assignment be a single equals, not a double equals? Otherwise what the program will see is effectively this:




if(event.type == SDL_QUIT)
{//SDL_QUIT event type = Closing (Xing Out) Window
false;
}
MichaelBarth
MichaelBarth
Oberon_Command is right. It should be quit = true;

Although in the future when you're doing events in SDL, it may be better for you to use a switch statement. If you're not doing many events, an if statement may be all you need, like in this case you're only checking for one in particular, so an if statement is fine. When you have many events, using a switch statement could save you from a lot of problems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.