From: <av...@us...> - 2012-02-26 19:42:21
|
Revision: 3776 http://sc2.svn.sourceforge.net/sc2/?rev=3776&view=rev Author: avolkov Date: 2012-02-26 19:42:15 +0000 (Sun, 26 Feb 2012) Log Message: ----------- More work towards exit cleanliness; bugs 50, 1149: * Some atexit() callbacks removed, to be called in order during clean exit (Abort key bypasses these) The only things called atexit() are now removeTempDir, SDL_Quit() and log messageboxes * gfxlib cleans up remaining SDL_Surfaces * Other cleanup improvements: the goal is to allow library cleanup funcs to be called more than once w/o crashing, and then decide which should and can be called atexit() safely. Modified Paths: -------------- trunk/sc2/src/libs/graphics/dcqueue.c trunk/sc2/src/libs/graphics/sdl/opengl.c trunk/sc2/src/libs/graphics/sdl/opengl.h trunk/sc2/src/libs/graphics/sdl/pure.c trunk/sc2/src/libs/graphics/sdl/pure.h trunk/sc2/src/libs/graphics/sdl/sdl_common.c trunk/sc2/src/libs/graphics/sdl/sdl_common.h trunk/sc2/src/libs/input/sdl/input.c trunk/sc2/src/libs/log/uqmlog.c trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c trunk/sc2/src/libs/sound/mixer/sdl/audiodrv_sdl.c trunk/sc2/src/libs/sound/openal/audiodrv_openal.c trunk/sc2/src/libs/task/tasklib.c trunk/sc2/src/uqm/globdata.c trunk/sc2/src/uqm.c Modified: trunk/sc2/src/libs/graphics/dcqueue.c =================================================================== --- trunk/sc2/src/libs/graphics/dcqueue.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/dcqueue.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -156,8 +156,17 @@ void Uninit_DrawCommandQueue (void) { - DestroyCondVar (RenderingCond); - DestroyRecursiveMutex (DCQ_Mutex); + if (RenderingCond) + { + DestroyCondVar (RenderingCond); + RenderingCond = 0; + } + + if (DCQ_Mutex) + { + DestroyRecursiveMutex (DCQ_Mutex); + DCQ_Mutex = 0; + } } void Modified: trunk/sc2/src/libs/graphics/sdl/opengl.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/opengl.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/opengl.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -274,6 +274,15 @@ return 0; } +void +TFB_GL_UninitGraphics (void) +{ + int i; + + for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + UnInit_Screen (&GL_Screens[i].scaled); +} + void TFB_GL_UploadTransitionScreen (void) { GL_Screens[TFB_SCREEN_TRANSITION].updated.x = 0; Modified: trunk/sc2/src/libs/graphics/sdl/opengl.h =================================================================== --- trunk/sc2/src/libs/graphics/sdl/opengl.h 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/opengl.h 2012-02-26 19:42:15 UTC (rev 3776) @@ -22,6 +22,7 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_GL_InitGraphics (int driver, int flags, int width, int height); +void TFB_GL_UninitGraphics (void); int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); void TFB_GL_UploadTransitionScreen (void); Modified: trunk/sc2/src/libs/graphics/sdl/pure.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/pure.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/pure.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -263,6 +263,14 @@ return 0; } +void +TFB_Pure_UninitGraphics (void) +{ + UnInit_Screen (&scaled_display); + UnInit_Screen (&fade_color_surface); + UnInit_Screen (&fade_temp); +} + static void ScanLines (SDL_Surface *dst, SDL_Rect *r) { Modified: trunk/sc2/src/libs/graphics/sdl/pure.h =================================================================== --- trunk/sc2/src/libs/graphics/sdl/pure.h 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/pure.h 2012-02-26 19:42:15 UTC (rev 3776) @@ -22,6 +22,7 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_Pure_InitGraphics (int driver, int flags, int width, int height); +void TFB_Pure_UninitGraphics (void); int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); void Scale_PerfTest (void); Modified: trunk/sc2/src/libs/graphics/sdl/sdl_common.c =================================================================== --- trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/sdl_common.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -52,6 +52,8 @@ volatile int QuitPosted = 0; volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE +static void TFB_PreQuit (void); + void TFB_PreInit (void) { @@ -76,8 +78,16 @@ log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ()); exit (EXIT_FAILURE); } + + atexit (TFB_PreQuit); } +static void +TFB_PreQuit (void) +{ + SDL_Quit (); +} + int TFB_ReInitGraphics (int driver, int flags, int width, int height) { @@ -129,15 +139,9 @@ int TFB_InitGraphics (int driver, int flags, int width, int height) { - int result, i; + int result; char caption[200]; - /* Null out screen pointers the first time */ - for (i = 0; i < TFB_GFX_NUMSCREENS; i++) - { - SDL_Screens[i] = NULL; - } - GfxFlags = flags; if (driver == TFB_GFXDRIVER_SDL_OPENGL) @@ -168,17 +172,25 @@ TFB_DrawCanvas_Initialize (); - atexit (TFB_UninitGraphics); - return 0; } void TFB_UninitGraphics (void) { + int i; + Uninit_DrawCommandQueue (); - // TODO: Uninit whatever the drivers have set up for us - SDL_Quit (); + + for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + UnInit_Screen (&SDL_Screens[i]); + + TFB_Pure_UninitGraphics (); +#ifdef HAVE_OPENGL + TFB_GL_UninitGraphics (); +#endif + + UnInit_Screen (&format_conv_surf); } void @@ -370,9 +382,18 @@ int ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h) { - if (*screen) - SDL_FreeSurface (*screen); + UnInit_Screen (screen); *screen = Create_Screen (templat, w, h); return *screen == 0 ? -1 : 0; } + +void +UnInit_Screen (SDL_Surface **screen) +{ + if (*screen == NULL) + return; + + SDL_FreeSurface (*screen); + *screen = NULL; +} Modified: trunk/sc2/src/libs/graphics/sdl/sdl_common.h =================================================================== --- trunk/sc2/src/libs/graphics/sdl/sdl_common.h 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/graphics/sdl/sdl_common.h 2012-02-26 19:42:15 UTC (rev 3776) @@ -50,5 +50,6 @@ SDL_Surface* Create_Screen (SDL_Surface *templat, int w, int h); int ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h); +void UnInit_Screen (SDL_Surface **screen); #endif Modified: trunk/sc2/src/libs/input/sdl/input.c =================================================================== --- trunk/sc2/src/libs/input/sdl/input.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/input/sdl/input.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -273,7 +273,6 @@ VControl_ResetInput (); InputInitialized = TRUE; - atexit (TFB_UninitInput); return 0; } Modified: trunk/sc2/src/libs/log/uqmlog.c =================================================================== --- trunk/sc2/src/libs/log/uqmlog.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/log/uqmlog.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -159,6 +159,7 @@ { qlock = 0; DestroyMutex (qmutex); + qmutex = 0; } return code; Modified: trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c =================================================================== --- trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/sound/mixer/nosound/audiodrv_nosound.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -146,8 +146,6 @@ return -1; } - atexit (unInitAudio); - PlaybackTask = AssignTask (PlaybackTaskFunc, 1024, "nosound audio playback"); Modified: trunk/sc2/src/libs/sound/mixer/sdl/audiodrv_sdl.c =================================================================== --- trunk/sc2/src/libs/sound/mixer/sdl/audiodrv_sdl.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/sound/mixer/sdl/audiodrv_sdl.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -212,8 +212,6 @@ return -1; } - atexit (unInitAudio); - SDL_PauseAudio (0); return 0; @@ -239,6 +237,7 @@ HFree (sbuffer); } DestroyMutex (soundSource[i].stream_mutex); + soundSource[i].stream_mutex = 0; mixSDL_DeleteSources (1, &soundSource[i].handle); } Modified: trunk/sc2/src/libs/sound/openal/audiodrv_openal.c =================================================================== --- trunk/sc2/src/libs/sound/openal/audiodrv_openal.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/sound/openal/audiodrv_openal.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -126,7 +126,6 @@ } *driver = openAL_Driver; - atexit (unInitAudio); alcContext = alcCreateContext (alcDevice, NULL); if (!alcContext) Modified: trunk/sc2/src/libs/task/tasklib.c =================================================================== --- trunk/sc2/src/libs/task/tasklib.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/libs/task/tasklib.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -124,7 +124,6 @@ { task_array[i].state_mutex = CreateMutex ("task manager lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_RESOURCE); } - atexit (CleanupTaskSystem); } void @@ -134,6 +133,7 @@ for (i = 0; i < TASK_MAX; ++i) { DestroyMutex (task_array[i].state_mutex); + task_array[i].state_mutex = 0; } } Modified: trunk/sc2/src/uqm/globdata.c =================================================================== --- trunk/sc2/src/uqm/globdata.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/uqm/globdata.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -46,9 +46,7 @@ GLOBDATA GlobData; -static BOOLEAN initedGameStructs = FALSE; - BYTE getGameState (int startBit, int endBit) { @@ -347,17 +345,6 @@ GLOBAL (autopilot.x) = ~0; GLOBAL (autopilot.y) = ~0; - /* In case the program is exited before the full game is terminated, - * make sure that the temporary files are deleted. - * This can be removed if we make sure if the full game is terminated - * before the game is exited. - * The initedSIS variable is added so the uninit won't happen more - * than once, as you can't remove the atexit function (when the full game - * ends). - */ - initedGameStructs = TRUE; - atexit (UninitGameStructures); - return (TRUE); } @@ -379,9 +366,6 @@ { HFLEETINFO hStarShip; - if (!initedGameStructs) - return; - UninitQueue (&GLOBAL (encounter_q)); UninitQueue (&GLOBAL (ip_group_q)); UninitQueue (&GLOBAL (npc_built_ship_q)); @@ -409,7 +393,6 @@ DestroyDrawable (ReleaseDrawable (PlayFrame)); PlayFrame = 0; - initedGameStructs = FALSE; } void Modified: trunk/sc2/src/uqm.c =================================================================== --- trunk/sc2/src/uqm.c 2012-02-25 20:15:23 UTC (rev 3775) +++ trunk/sc2/src/uqm.c 2012-02-26 19:42:15 UTC (rev 3776) @@ -464,14 +464,14 @@ * tasks might still be using it */ if (MainExited) { - // Not yet: TFB_UninitInput (); + TFB_UninitInput (); unInitAudio (); uninit_communication (); - // TODO: Merge into TFB_UninitGraphics when it goes live + TFB_PurgeDanglingGraphics (); // Purge above refers to colormaps which have to be still up UninitColorMaps (); - // Not yet: TFB_UninitGraphics (); + TFB_UninitGraphics (); #ifdef NETPLAY NetManager_uninit (); @@ -481,7 +481,7 @@ Callback_uninit (); Alarm_uninit (); - // Not yet: CleanupTaskSystem (); + CleanupTaskSystem (); UnInitTimeSystem (); #if 0 unInitTempDir (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |