Sign in to follow this  

[SDL] clicking 'X' does not close project

This topic is 4692 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

Hi, For some reason in my SDL app when I click on the X in the title bar it will not close the app, and sometimes it creates an illegal operation. Is there some special code I am suppost to put in to make it operate right?

Share this post


Link to post
Share on other sites
Yes, you have to handle the exit condition in your code to prevent further execution of your program. Here is the example from the Cone3D main game loop.

int done=0;

while(done == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}

.. Draw function calling goes here ..
}





Do not forget to call SDL_Quit at the end if you did not atexit it. That should allow you to exit now. Basically after the done variable is set to true, the loop exits and the program is done. You can add deinitialization code after the loop before you return as well. Here is the Cone3D tutorial I refrenced. I think that should solveyour problems, if not then you will need to paste code because something is out of order I believe.

- Drew

Share this post


Link to post
Share on other sites

This topic is 4692 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