Sign in to follow this  

SDL Event Handling

This topic is 2043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by nyl2000

Share this post


Link to post
Share on other sites
[code]

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

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


[code]

if(event.type == SDL_QUIT)
{//SDL_QUIT event type = Closing (Xing Out) Window
false;
}
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this