Mercurial > repos > blastem
comparison render_sdl.c @ 655:38006d43f5a3
Avoid calling atexit(SDL_Quit) until after OpenGL initialization to avoid a segfault on exit when using fglrx
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 01 Jan 2015 17:36:23 -0800 |
parents | b76d2a628ab9 |
children | 019d27995e32 |
comparison
equal
deleted
inserted
replaced
654:98927f1b005b | 655:38006d43f5a3 |
---|---|
218 { | 218 { |
219 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { | 219 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { |
220 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); | 220 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); |
221 exit(1); | 221 exit(1); |
222 } | 222 } |
223 atexit(SDL_Quit); | |
224 atexit(render_close_audio); | |
225 printf("width: %d, height: %d\n", width, height); | 223 printf("width: %d, height: %d\n", width, height); |
226 uint32_t flags = SDL_ANYFORMAT; | 224 uint32_t flags = SDL_ANYFORMAT; |
227 | 225 |
228 #ifndef DISABLE_OPENGL | 226 #ifndef DISABLE_OPENGL |
229 if (use_gl) | 227 if (use_gl) |
248 } | 246 } |
249 } | 247 } |
250 screen = SDL_SetVideoMode(width, height, 32, flags); | 248 screen = SDL_SetVideoMode(width, height, 32, flags); |
251 if (!screen) { | 249 if (!screen) { |
252 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError()); | 250 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError()); |
251 SDL_Quit(); | |
253 exit(1); | 252 exit(1); |
254 } | 253 } |
255 if (!use_gl && screen->format->BytesPerPixel != 2 && screen->format->BytesPerPixel != 4) { | 254 if (!use_gl && screen->format->BytesPerPixel != 2 && screen->format->BytesPerPixel != 4) { |
256 fprintf(stderr, "BlastEm requires a 16-bit or 32-bit surface, SDL returned a %d-bit surface\n", screen->format->BytesPerPixel * 8); | 255 fprintf(stderr, "BlastEm requires a 16-bit or 32-bit surface, SDL returned a %d-bit surface\n", screen->format->BytesPerPixel * 8); |
256 SDL_Quit(); | |
257 exit(1); | 257 exit(1); |
258 } | 258 } |
259 #ifndef DISABLE_OPENGL | 259 #ifndef DISABLE_OPENGL |
260 //TODO: fallback on standard rendering if OpenGL 2.0 is unavailable or if init fails | 260 //TODO: fallback on standard rendering if OpenGL 2.0 is unavailable or if init fails |
261 if (use_gl) | 261 if (use_gl) |
262 { | 262 { |
263 GLenum res = glewInit(); | 263 GLenum res = glewInit(); |
264 if (res != GLEW_OK) { | 264 if (res != GLEW_OK) { |
265 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); | 265 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); |
266 SDL_Quit(); | |
266 exit(1); | 267 exit(1); |
267 } | 268 } |
268 if (!GLEW_VERSION_2_0) { | 269 if (!GLEW_VERSION_2_0) { |
269 fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr); | 270 fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr); |
271 SDL_Quit(); | |
270 exit(1); | 272 exit(1); |
271 } | 273 } |
272 float aspect = (float)width / height; | 274 float aspect = (float)width / height; |
273 if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_ptr_default(config, "videoaspect", "normal"), "stretch")) { | 275 if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_ptr_default(config, "videoaspect", "normal"), "stretch")) { |
274 for (int i = 0; i < 4; i++) | 276 for (int i = 0; i < 4; i++) |
325 desired.callback = audio_callback; | 327 desired.callback = audio_callback; |
326 desired.userdata = NULL; | 328 desired.userdata = NULL; |
327 | 329 |
328 if (SDL_OpenAudio(&desired, &actual) < 0) { | 330 if (SDL_OpenAudio(&desired, &actual) < 0) { |
329 fprintf(stderr, "Unable to open SDL audio: %s\n", SDL_GetError()); | 331 fprintf(stderr, "Unable to open SDL audio: %s\n", SDL_GetError()); |
332 SDL_Quit(); | |
330 exit(1); | 333 exit(1); |
331 } | 334 } |
332 buffer_samples = actual.samples; | 335 buffer_samples = actual.samples; |
333 sample_rate = actual.freq; | 336 sample_rate = actual.freq; |
334 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples); | 337 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples); |
343 if (joy) { | 346 if (joy) { |
344 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); | 347 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
345 } | 348 } |
346 } | 349 } |
347 SDL_JoystickEventState(SDL_ENABLE); | 350 SDL_JoystickEventState(SDL_ENABLE); |
351 | |
352 atexit(SDL_Quit); | |
353 atexit(render_close_audio); | |
348 } | 354 } |
349 #ifndef DISABLE_OPENGL | 355 #ifndef DISABLE_OPENGL |
350 void render_context_gl(vdp_context * context) | 356 void render_context_gl(vdp_context * context) |
351 { | 357 { |
352 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); | 358 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); |