comparison test/testerror.c @ 1151:be9c9c8f6d53

Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe if SDL is built with a non-cdecl calling convention, and it's just generally bad practice anyhow. Now programs explicitly call SDL_Quit() where appropriate, wrap SDL_Quit() in a cdecl function where it can't be avoided, and rely on the parachute where a crash might have hit the atexit() before (these ARE test programs, after all!).
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 28 Sep 2005 11:36:20 +0000
parents 74212992fb08
children 14717b52abc0
comparison
equal deleted inserted replaced
1150:7d8e1925f35b 1151:be9c9c8f6d53
7 7
8 #include "SDL.h" 8 #include "SDL.h"
9 #include "SDL_thread.h" 9 #include "SDL_thread.h"
10 10
11 static int alive = 0; 11 static int alive = 0;
12
13 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
14 static void quit(int rc)
15 {
16 SDL_Quit();
17 exit(rc);
18 }
12 19
13 int ThreadFunc(void *data) 20 int ThreadFunc(void *data)
14 { 21 {
15 /* Set the child thread error string */ 22 /* Set the child thread error string */
16 SDL_SetError("Thread %s (%d) had a problem: %s", 23 SDL_SetError("Thread %s (%d) had a problem: %s",
28 SDL_Thread *thread; 35 SDL_Thread *thread;
29 36
30 /* Load the SDL library */ 37 /* Load the SDL library */
31 if ( SDL_Init(0) < 0 ) { 38 if ( SDL_Init(0) < 0 ) {
32 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 39 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
33 exit(1); 40 return(1);
34 } 41 }
35 atexit(SDL_Quit);
36 42
37 /* Set the error value for the main thread */ 43 /* Set the error value for the main thread */
38 SDL_SetError("No worries"); 44 SDL_SetError("No worries");
39 45
40 alive = 1; 46 alive = 1;
41 thread = SDL_CreateThread(ThreadFunc, "#1"); 47 thread = SDL_CreateThread(ThreadFunc, "#1");
42 if ( thread == NULL ) { 48 if ( thread == NULL ) {
43 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); 49 fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
44 exit(1); 50 quit(1);
45 } 51 }
46 SDL_Delay(5*1000); 52 SDL_Delay(5*1000);
47 printf("Waiting for thread #1\n"); 53 printf("Waiting for thread #1\n");
48 alive = 0; 54 alive = 0;
49 SDL_WaitThread(thread, NULL); 55 SDL_WaitThread(thread, NULL);
50 56
51 printf("Main thread error string: %s\n", SDL_GetError()); 57 printf("Main thread error string: %s\n", SDL_GetError());
52 58
59 SDL_Quit();
53 return(0); 60 return(0);
54 } 61 }