Jump to content
  • Advertisement
Sign in to follow this  
Thrust

[SDL] clicking 'X' does not close project

This topic is 4908 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!