diff --git a/sc2/ChangeLog b/sc2/ChangeLog index bb253ad18..e1a4e5694 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.4: +- Fixed segfault when shutting down because video could not be initialized + (bug #683), - Michael - Fixed crash when restarting Sa-Matra battle after abort (bug #700) -Alex - Some cleanups, enabling successful build with GCC 4 (bug #710), mostly from Ville Skyttà - SvdB diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.c b/sc2/src/sc2code/libs/graphics/sdl/opengl.c index bb7e22ffd..0d6343298 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.c +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.c @@ -101,6 +101,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) videomode_flags = SDL_OPENGL; if (flags & TFB_GFXFLAGS_FULLSCREEN) videomode_flags |= SDL_FULLSCREEN; + videomode_flags |= SDL_ANYFORMAT; SDL_Video = SDL_SetVideoMode (ScreenWidthActual, ScreenHeightActual, bpp, videomode_flags); @@ -109,7 +110,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) fprintf (stderr, "Couldn't set OpenGL %ix%ix%i video mode: %s\n", ScreenWidthActual, ScreenHeightActual, bpp, SDL_GetError ()); - exit (-1); + return -1; } else { @@ -135,7 +136,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) if (scaled_display == NULL) { fprintf (stderr, "Couldn't create scaled_display: %s\n", SDL_GetError()); - exit(-1); + return -1; } if (scaled_transition) { @@ -147,7 +148,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) if (scaled_transition == NULL) { fprintf (stderr, "Couldn't create scaled_transition: %s\n", SDL_GetError()); - exit(-1); + return -1; } texture_width = 1024; @@ -169,7 +170,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int bpp) if (format_conv_surf == NULL) { fprintf (stderr, "Couldn't create format_conv_surf: %s\n", SDL_GetError()); - exit(-1); + return -1; } if (GfxFlags & TFB_GFXFLAGS_SCALE_BILINEAR || @@ -234,7 +235,11 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height, int bpp) ScreenWidth = 320; ScreenHeight = 240; - TFB_GL_ConfigureVideo (driver, flags, width, height, bpp); + if (TFB_GL_ConfigureVideo (driver, flags, width, height, bpp)) + { + fprintf (stderr, "Could not initialize video: no fallback at start of program!\n"); + exit (-1); + } // pre-compute the RGB->YUV transformations Scale_PrepYUV(); diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.c b/sc2/src/sc2code/libs/graphics/sdl/pure.c index 6bd4273c6..bd5677e0d 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.c +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.c @@ -74,7 +74,7 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int bpp) fprintf (stderr, "Couldn't set %ix%ix%i video mode: %s\n", ScreenWidthActual, ScreenHeightActual, bpp, SDL_GetError ()); - exit(-1); + return -1; } else { @@ -89,7 +89,7 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int bpp) if (test_extra == NULL) { fprintf (stderr, "Couldn't create back buffer: %s\n", SDL_GetError()); - exit(-1); + return -1; } for (i = 0; i < TFB_GFX_NUMSCREENS; i++) @@ -127,7 +127,7 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int bpp) { fprintf (stderr, "Fatal error: SDL_Video and SDL_Screen bpp doesn't match (%d vs. %d)\n", SDL_Video->format->BytesPerPixel,SDL_Screen->format->BytesPerPixel); - exit(-1); + return -1; } return 0; @@ -154,7 +154,11 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height, int bpp) ScreenWidth = 320; ScreenHeight = 240; - TFB_Pure_ConfigureVideo (driver, flags, width, height, bpp); + if (TFB_Pure_ConfigureVideo (driver, flags, width, height, bpp)) + { + fprintf (stderr, "Could not initialize video: no fallback at start of program!\n"); + exit (-1); + } // pre-compute the RGB->YUV transformations Scale_PrepYUV(); diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 5c22ed50b..58bd87cdb 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -121,8 +121,6 @@ TFB_InitGraphics (int driver, int flags, int width, int height, int bpp) exit(-1); } - atexit (TFB_UninitGraphics); - GfxFlags = flags; if (driver == TFB_GFXDRIVER_SDL_OPENGL) @@ -156,6 +154,8 @@ TFB_InitGraphics (int driver, int flags, int width, int height, int bpp) RenderingCond = CreateCondVar ("DCQ empty", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); + atexit (TFB_UninitGraphics); + return 0; }