Mercurial > sdl-ios-xcode
comparison test/testdyngl.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 | 8e20c48a9c13 |
children | 2b7e0180a72c |
comparison
equal
deleted
inserted
replaced
1150:7d8e1925f35b | 1151:be9c9c8f6d53 |
---|---|
21 | 21 |
22 #ifdef HAVE_OPENGL | 22 #ifdef HAVE_OPENGL |
23 | 23 |
24 #include "SDL_opengl.h" | 24 #include "SDL_opengl.h" |
25 | 25 |
26 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | |
27 static void quit(int rc) | |
28 { | |
29 SDL_Quit(); | |
30 exit(rc); | |
31 } | |
32 | |
26 void* get_funcaddr(const char* p) | 33 void* get_funcaddr(const char* p) |
27 { | 34 { |
28 void* f=SDL_GL_GetProcAddress(p); | 35 void* f=SDL_GL_GetProcAddress(p); |
29 if (f) | 36 if (f) |
30 { | 37 { |
31 return f; | 38 return f; |
32 } | 39 } |
33 else | 40 else |
34 { | 41 { |
35 printf("Unable to get function pointer for %s\n",p); | 42 printf("Unable to get function pointer for %s\n",p); |
36 exit(1); | 43 quit(1); |
37 } | 44 } |
38 } | 45 } |
39 | 46 |
40 typedef struct | 47 typedef struct |
41 { | 48 { |
102 } | 109 } |
103 | 110 |
104 if (SDL_Init(SDL_INIT_VIDEO)<0) | 111 if (SDL_Init(SDL_INIT_VIDEO)<0) |
105 { | 112 { |
106 printf("Unable to init SDL : %s\n",SDL_GetError()); | 113 printf("Unable to init SDL : %s\n",SDL_GetError()); |
107 exit(1); | 114 return(1); |
108 } | 115 } |
109 | 116 |
110 atexit(SDL_Quit); | |
111 | |
112 if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0) | 117 if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0) |
113 { | 118 { |
114 printf("Unable to set GL attribute : %s\n",SDL_GetError()); | 119 printf("Unable to set GL attribute : %s\n",SDL_GetError()); |
115 exit(1); | 120 quit(1); |
116 } | 121 } |
117 | 122 |
118 if (SDL_GL_LoadLibrary(gl_library)<0) | 123 if (SDL_GL_LoadLibrary(gl_library)<0) |
119 { | 124 { |
120 printf("Unable to dynamically open GL lib : %s\n",SDL_GetError()); | 125 printf("Unable to dynamically open GL lib : %s\n",SDL_GetError()); |
121 exit(1); | 126 quit(1); |
122 } | 127 } |
123 | 128 |
124 if (SDL_SetVideoMode(640,480,0,SDL_OPENGL)==NULL) | 129 if (SDL_SetVideoMode(640,480,0,SDL_OPENGL)==NULL) |
125 { | 130 { |
126 printf("Unable to open video mode : %s\n",SDL_GetError()); | 131 printf("Unable to open video mode : %s\n",SDL_GetError()); |
127 exit(1); | 132 quit(1); |
128 } | 133 } |
129 | 134 |
130 /* Set the window manager title bar */ | 135 /* Set the window manager title bar */ |
131 SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" ); | 136 SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" ); |
132 | 137 |