comparison playsound/playsound.c @ 572:7815c90ba552

Don't force quit in signal handler, since we might double-free things. Instead we set a flag and clean up normally.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 24 Jan 2010 13:45:18 -0500
parents 3b8748455aff
children 1911fc597c69
comparison
equal deleted inserted replaced
571:3b8748455aff 572:7815c90ba552
310 { 310 {
311 static Uint32 last_sigint = 0; 311 static Uint32 last_sigint = 0;
312 Uint32 ticks = SDL_GetTicks(); 312 Uint32 ticks = SDL_GetTicks();
313 313
314 assert(signum == SIGINT); 314 assert(signum == SIGINT);
315 315 if (done_flag < 0)
316 if ((last_sigint != 0) && (ticks - last_sigint < 500)) 316 return; /* mashing CTRL-C, we get it already. */
317 { 317
318 SDL_PauseAudio(1); 318 done_flag = ((last_sigint != 0) && (ticks - last_sigint < 500)) ? -1 : 1;
319 SDL_CloseAudio(); 319 last_sigint = ticks;
320 Sound_Quit();
321 SDL_Quit();
322 deinit_archive();
323 exit(1);
324 } /* if */
325
326 else
327 {
328 last_sigint = ticks;
329 done_flag = 1;
330 } /* else */
331 } /* sigint_catcher */ 320 } /* sigint_catcher */
332 #endif 321 #endif
333 322
334 323
335 /* global decoding state. */ 324 /* global decoding state. */
1049 1038
1050 SDL_CloseAudio(); /* reopen with next sample's format if possible */ 1039 SDL_CloseAudio(); /* reopen with next sample's format if possible */
1051 Sound_FreeSample(sample); 1040 Sound_FreeSample(sample);
1052 1041
1053 close_archive(filename); 1042 close_archive(filename);
1043
1044 if (done_flag < 0)
1045 break;
1054 } /* for */ 1046 } /* for */
1055 1047
1056 Sound_Quit(); 1048 Sound_Quit();
1057 SDL_Quit(); 1049 SDL_Quit();
1058 deinit_archive(); 1050 deinit_archive();
1059 return(0); 1051 return((done_flag < 0) ? 1 : 0);
1060 } /* main */ 1052 } /* main */
1061 1053
1062 /* end of playsound.c ... */ 1054 /* end of playsound.c ... */
1063 1055