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. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3776 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -156,8 +156,17 @@ Init_DrawCommandQueue (void)
|
||||
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
|
||||
|
||||
@@ -274,6 +274,15 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height)
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -263,6 +263,14 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height)
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ TFB_GRAPHICS_BACKEND *graphics_backend = NULL;
|
||||
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,6 +78,14 @@ TFB_PreInit (void)
|
||||
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
|
||||
@@ -129,15 +139,9 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
||||
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_InitGraphics (int driver, int flags, int width, int height)
|
||||
|
||||
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 @@ Create_Screen (SDL_Surface *templat, int w, int h)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -50,5 +50,6 @@ SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface);
|
||||
|
||||
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
|
||||
|
||||
@@ -273,7 +273,6 @@ TFB_InitInput (int driver, int flags)
|
||||
VControl_ResetInput ();
|
||||
InputInitialized = TRUE;
|
||||
|
||||
atexit (TFB_UninitInput);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,6 +159,7 @@ log_exit (int code)
|
||||
{
|
||||
qlock = 0;
|
||||
DestroyMutex (qmutex);
|
||||
qmutex = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
||||
@@ -146,8 +146,6 @@ noSound_Init (audio_Driver *driver, sint32 flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
atexit (unInitAudio);
|
||||
|
||||
PlaybackTask = AssignTask (PlaybackTaskFunc, 1024,
|
||||
"nosound audio playback");
|
||||
|
||||
|
||||
@@ -212,8 +212,6 @@ mixSDL_Init (audio_Driver *driver, sint32 flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
atexit (unInitAudio);
|
||||
|
||||
SDL_PauseAudio (0);
|
||||
|
||||
return 0;
|
||||
@@ -239,6 +237,7 @@ mixSDL_Uninit (void)
|
||||
HFree (sbuffer);
|
||||
}
|
||||
DestroyMutex (soundSource[i].stream_mutex);
|
||||
soundSource[i].stream_mutex = 0;
|
||||
|
||||
mixSDL_DeleteSources (1, &soundSource[i].handle);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,6 @@ openAL_Init (audio_Driver *driver, sint32 flags)
|
||||
}
|
||||
|
||||
*driver = openAL_Driver;
|
||||
atexit (unInitAudio);
|
||||
|
||||
alcContext = alcCreateContext (alcDevice, NULL);
|
||||
if (!alcContext)
|
||||
|
||||
@@ -124,7 +124,6 @@ InitTaskSystem (void)
|
||||
{
|
||||
task_array[i].state_mutex = CreateMutex ("task manager lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_RESOURCE);
|
||||
}
|
||||
atexit (CleanupTaskSystem);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -134,6 +133,7 @@ CleanupTaskSystem (void)
|
||||
for (i = 0; i < TASK_MAX; ++i)
|
||||
{
|
||||
DestroyMutex (task_array[i].state_mutex);
|
||||
task_array[i].state_mutex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -464,14 +464,14 @@ main (int argc, char *argv[])
|
||||
* 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 @@ main (int argc, char *argv[])
|
||||
Callback_uninit ();
|
||||
Alarm_uninit ();
|
||||
|
||||
// Not yet: CleanupTaskSystem ();
|
||||
CleanupTaskSystem ();
|
||||
UnInitTimeSystem ();
|
||||
#if 0
|
||||
unInitTempDir ();
|
||||
|
||||
@@ -46,8 +46,6 @@ FRAME PlayFrame;
|
||||
|
||||
GLOBDATA GlobData;
|
||||
|
||||
static BOOLEAN initedGameStructs = FALSE;
|
||||
|
||||
|
||||
BYTE
|
||||
getGameState (int startBit, int endBit)
|
||||
@@ -347,17 +345,6 @@ InitGameStructures (void)
|
||||
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 @@ UninitGameStructures (void)
|
||||
{
|
||||
HFLEETINFO hStarShip;
|
||||
|
||||
if (!initedGameStructs)
|
||||
return;
|
||||
|
||||
UninitQueue (&GLOBAL (encounter_q));
|
||||
UninitQueue (&GLOBAL (ip_group_q));
|
||||
UninitQueue (&GLOBAL (npc_built_ship_q));
|
||||
@@ -409,7 +393,6 @@ UninitGameStructures (void)
|
||||
|
||||
DestroyDrawable (ReleaseDrawable (PlayFrame));
|
||||
PlayFrame = 0;
|
||||
initedGameStructs = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user