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
|
void
|
||||||
Uninit_DrawCommandQueue (void)
|
Uninit_DrawCommandQueue (void)
|
||||||
{
|
{
|
||||||
|
if (RenderingCond)
|
||||||
|
{
|
||||||
DestroyCondVar (RenderingCond);
|
DestroyCondVar (RenderingCond);
|
||||||
|
RenderingCond = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DCQ_Mutex)
|
||||||
|
{
|
||||||
DestroyRecursiveMutex (DCQ_Mutex);
|
DestroyRecursiveMutex (DCQ_Mutex);
|
||||||
|
DCQ_Mutex = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -274,6 +274,15 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height)
|
|||||||
return 0;
|
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)
|
void TFB_GL_UploadTransitionScreen (void)
|
||||||
{
|
{
|
||||||
GL_Screens[TFB_SCREEN_TRANSITION].updated.x = 0;
|
GL_Screens[TFB_SCREEN_TRANSITION].updated.x = 0;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "libs/graphics/sdl/sdl_common.h"
|
#include "libs/graphics/sdl/sdl_common.h"
|
||||||
|
|
||||||
int TFB_GL_InitGraphics (int driver, int flags, int width, int height);
|
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);
|
int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen);
|
||||||
void TFB_GL_UploadTransitionScreen (void);
|
void TFB_GL_UploadTransitionScreen (void);
|
||||||
|
|
||||||
|
|||||||
@@ -263,6 +263,14 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TFB_Pure_UninitGraphics (void)
|
||||||
|
{
|
||||||
|
UnInit_Screen (&scaled_display);
|
||||||
|
UnInit_Screen (&fade_color_surface);
|
||||||
|
UnInit_Screen (&fade_temp);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ScanLines (SDL_Surface *dst, SDL_Rect *r)
|
ScanLines (SDL_Surface *dst, SDL_Rect *r)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "libs/graphics/sdl/sdl_common.h"
|
#include "libs/graphics/sdl/sdl_common.h"
|
||||||
|
|
||||||
int TFB_Pure_InitGraphics (int driver, int flags, int width, int height);
|
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);
|
int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen);
|
||||||
void Scale_PerfTest (void);
|
void Scale_PerfTest (void);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ TFB_GRAPHICS_BACKEND *graphics_backend = NULL;
|
|||||||
volatile int QuitPosted = 0;
|
volatile int QuitPosted = 0;
|
||||||
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
|
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
|
||||||
|
|
||||||
|
static void TFB_PreQuit (void);
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_PreInit (void)
|
TFB_PreInit (void)
|
||||||
{
|
{
|
||||||
@@ -76,6 +78,14 @@ TFB_PreInit (void)
|
|||||||
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
|
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atexit (TFB_PreQuit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
TFB_PreQuit (void)
|
||||||
|
{
|
||||||
|
SDL_Quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -129,15 +139,9 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
|||||||
int
|
int
|
||||||
TFB_InitGraphics (int driver, int flags, int width, int height)
|
TFB_InitGraphics (int driver, int flags, int width, int height)
|
||||||
{
|
{
|
||||||
int result, i;
|
int result;
|
||||||
char caption[200];
|
char caption[200];
|
||||||
|
|
||||||
/* Null out screen pointers the first time */
|
|
||||||
for (i = 0; i < TFB_GFX_NUMSCREENS; i++)
|
|
||||||
{
|
|
||||||
SDL_Screens[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GfxFlags = flags;
|
GfxFlags = flags;
|
||||||
|
|
||||||
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
|
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
|
||||||
@@ -168,17 +172,25 @@ TFB_InitGraphics (int driver, int flags, int width, int height)
|
|||||||
|
|
||||||
TFB_DrawCanvas_Initialize ();
|
TFB_DrawCanvas_Initialize ();
|
||||||
|
|
||||||
atexit (TFB_UninitGraphics);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_UninitGraphics (void)
|
TFB_UninitGraphics (void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
Uninit_DrawCommandQueue ();
|
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
|
void
|
||||||
@@ -370,9 +382,18 @@ Create_Screen (SDL_Surface *templat, int w, int h)
|
|||||||
int
|
int
|
||||||
ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h)
|
ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h)
|
||||||
{
|
{
|
||||||
if (*screen)
|
UnInit_Screen (screen);
|
||||||
SDL_FreeSurface (*screen);
|
|
||||||
*screen = Create_Screen (templat, w, h);
|
*screen = Create_Screen (templat, w, h);
|
||||||
|
|
||||||
return *screen == 0 ? -1 : 0;
|
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);
|
SDL_Surface* Create_Screen (SDL_Surface *templat, int w, int h);
|
||||||
int ReInit_Screen (SDL_Surface **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
|
#endif
|
||||||
|
|||||||
@@ -273,7 +273,6 @@ TFB_InitInput (int driver, int flags)
|
|||||||
VControl_ResetInput ();
|
VControl_ResetInput ();
|
||||||
InputInitialized = TRUE;
|
InputInitialized = TRUE;
|
||||||
|
|
||||||
atexit (TFB_UninitInput);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ log_exit (int code)
|
|||||||
{
|
{
|
||||||
qlock = 0;
|
qlock = 0;
|
||||||
DestroyMutex (qmutex);
|
DestroyMutex (qmutex);
|
||||||
|
qmutex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|||||||
@@ -146,8 +146,6 @@ noSound_Init (audio_Driver *driver, sint32 flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
atexit (unInitAudio);
|
|
||||||
|
|
||||||
PlaybackTask = AssignTask (PlaybackTaskFunc, 1024,
|
PlaybackTask = AssignTask (PlaybackTaskFunc, 1024,
|
||||||
"nosound audio playback");
|
"nosound audio playback");
|
||||||
|
|
||||||
|
|||||||
@@ -212,8 +212,6 @@ mixSDL_Init (audio_Driver *driver, sint32 flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
atexit (unInitAudio);
|
|
||||||
|
|
||||||
SDL_PauseAudio (0);
|
SDL_PauseAudio (0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -239,6 +237,7 @@ mixSDL_Uninit (void)
|
|||||||
HFree (sbuffer);
|
HFree (sbuffer);
|
||||||
}
|
}
|
||||||
DestroyMutex (soundSource[i].stream_mutex);
|
DestroyMutex (soundSource[i].stream_mutex);
|
||||||
|
soundSource[i].stream_mutex = 0;
|
||||||
|
|
||||||
mixSDL_DeleteSources (1, &soundSource[i].handle);
|
mixSDL_DeleteSources (1, &soundSource[i].handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ openAL_Init (audio_Driver *driver, sint32 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*driver = openAL_Driver;
|
*driver = openAL_Driver;
|
||||||
atexit (unInitAudio);
|
|
||||||
|
|
||||||
alcContext = alcCreateContext (alcDevice, NULL);
|
alcContext = alcCreateContext (alcDevice, NULL);
|
||||||
if (!alcContext)
|
if (!alcContext)
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ InitTaskSystem (void)
|
|||||||
{
|
{
|
||||||
task_array[i].state_mutex = CreateMutex ("task manager lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_RESOURCE);
|
task_array[i].state_mutex = CreateMutex ("task manager lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_RESOURCE);
|
||||||
}
|
}
|
||||||
atexit (CleanupTaskSystem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -134,6 +133,7 @@ CleanupTaskSystem (void)
|
|||||||
for (i = 0; i < TASK_MAX; ++i)
|
for (i = 0; i < TASK_MAX; ++i)
|
||||||
{
|
{
|
||||||
DestroyMutex (task_array[i].state_mutex);
|
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 */
|
* tasks might still be using it */
|
||||||
if (MainExited)
|
if (MainExited)
|
||||||
{
|
{
|
||||||
// Not yet: TFB_UninitInput ();
|
TFB_UninitInput ();
|
||||||
unInitAudio ();
|
unInitAudio ();
|
||||||
uninit_communication ();
|
uninit_communication ();
|
||||||
// TODO: Merge into TFB_UninitGraphics when it goes live
|
|
||||||
TFB_PurgeDanglingGraphics ();
|
TFB_PurgeDanglingGraphics ();
|
||||||
// Purge above refers to colormaps which have to be still up
|
// Purge above refers to colormaps which have to be still up
|
||||||
UninitColorMaps ();
|
UninitColorMaps ();
|
||||||
// Not yet: TFB_UninitGraphics ();
|
TFB_UninitGraphics ();
|
||||||
|
|
||||||
#ifdef NETPLAY
|
#ifdef NETPLAY
|
||||||
NetManager_uninit ();
|
NetManager_uninit ();
|
||||||
@@ -481,7 +481,7 @@ main (int argc, char *argv[])
|
|||||||
Callback_uninit ();
|
Callback_uninit ();
|
||||||
Alarm_uninit ();
|
Alarm_uninit ();
|
||||||
|
|
||||||
// Not yet: CleanupTaskSystem ();
|
CleanupTaskSystem ();
|
||||||
UnInitTimeSystem ();
|
UnInitTimeSystem ();
|
||||||
#if 0
|
#if 0
|
||||||
unInitTempDir ();
|
unInitTempDir ();
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ FRAME PlayFrame;
|
|||||||
|
|
||||||
GLOBDATA GlobData;
|
GLOBDATA GlobData;
|
||||||
|
|
||||||
static BOOLEAN initedGameStructs = FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
BYTE
|
BYTE
|
||||||
getGameState (int startBit, int endBit)
|
getGameState (int startBit, int endBit)
|
||||||
@@ -347,17 +345,6 @@ InitGameStructures (void)
|
|||||||
GLOBAL (autopilot.x) = ~0;
|
GLOBAL (autopilot.x) = ~0;
|
||||||
GLOBAL (autopilot.y) = ~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);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,9 +366,6 @@ UninitGameStructures (void)
|
|||||||
{
|
{
|
||||||
HFLEETINFO hStarShip;
|
HFLEETINFO hStarShip;
|
||||||
|
|
||||||
if (!initedGameStructs)
|
|
||||||
return;
|
|
||||||
|
|
||||||
UninitQueue (&GLOBAL (encounter_q));
|
UninitQueue (&GLOBAL (encounter_q));
|
||||||
UninitQueue (&GLOBAL (ip_group_q));
|
UninitQueue (&GLOBAL (ip_group_q));
|
||||||
UninitQueue (&GLOBAL (npc_built_ship_q));
|
UninitQueue (&GLOBAL (npc_built_ship_q));
|
||||||
@@ -409,7 +393,6 @@ UninitGameStructures (void)
|
|||||||
|
|
||||||
DestroyDrawable (ReleaseDrawable (PlayFrame));
|
DestroyDrawable (ReleaseDrawable (PlayFrame));
|
||||||
PlayFrame = 0;
|
PlayFrame = 0;
|
||||||
initedGameStructs = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user