Commit 8b60221c authored by Evan Ramos's avatar Evan Ramos
Browse files

WIP: Remove all atexit calls and call uninitsystem() from engineUnInit()

parent f9a2611f
......@@ -150,18 +150,10 @@ int SDLDrv_PCM_Init(int *mixrate, int *numchannels, void * initdata)
if (Initialised)
SDLDrv_PCM_Shutdown();
#if SDL_MAJOR_VERSION >= 2
else if (SDLAudioDriverNameEnv == nullptr)
if (!SDLAudioDriverNameEnv)
{
static int done;
if (!done)
{
if (auto s = SDL_getenv("SDL_AUDIODRIVER"))
SDLAudioDriverNameEnv = Xstrdup(s);
atexit(SDLDrv_Cleanup);
done = true;
}
if (auto s = SDL_getenv("SDL_AUDIODRIVER"))
SDLAudioDriverNameEnv = Xstrdup(s);
}
if (SDLAudioDriverName[0])
......@@ -286,6 +278,9 @@ void SDLDrv_PCM_Shutdown(void)
StartedSDL = 0;
Initialised = 0;
#if SDL_MAJOR_VERSION >= 2
SDLDrv_Cleanup();
#endif
}
int SDLDrv_PCM_BeginPlayback(char *BufferStart, int BufferSize,
......
......@@ -5364,7 +5364,7 @@ extern "C" {
#ifdef _WIN32
static int is_enet_initialized = 0;
int enet_initialize(void) {
WORD versionRequested = MAKEWORD(1, 1);
......@@ -5380,12 +5380,16 @@ extern "C" {
}
timeBeginPeriod(1);
is_enet_initialized = 1;
return 0;
}
void enet_deinitialize(void) {
timeEndPeriod(1);
WSACleanup();
if (is_enet_initialized) {
timeEndPeriod(1);
WSACleanup();
is_enet_initialized = 0;
}
}
enet_uint64 enet_host_random_seed(void) {
......
......@@ -8886,6 +8886,8 @@ void engineUnInit(void)
pskynummultis = 0;
DO_FREE_AND_NULL(g_defNamePtr);
uninitsystem();
}
......
......@@ -809,8 +809,6 @@ void OSD_Init(void)
OSD_RegisterFunction("listsymbols", "listsymbols: lists all registered functions, cvars and aliases", osdfunc_listsymbols);
OSD_RegisterFunction("toggle", "toggle: toggles the value of a boolean cvar", osdfunc_toggle);
OSD_RegisterFunction("unalias", "unalias: removes a command alias", osdfunc_unalias);
// atexit(OSD_Cleanup);
}
......
......@@ -689,8 +689,6 @@ int32_t initsystem(void)
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
#endif
atexit(uninitsystem);
timerInit(CLOCKTICKSPERSECOND);
frameplace = 0;
......
......@@ -84,8 +84,6 @@ int32_t initsystem(void)
#endif
}
atexit(uninitsystem);
frameplace = 0;
lockcount = 0;
......
......@@ -471,8 +471,6 @@ int32_t initsystem(void)
memset(curpalette, 0, sizeof(palette_t) * 256);
atexit(uninitsystem);
timerInit(CLOCKTICKSPERSECOND);
frameplace=0;
......
......@@ -281,7 +281,28 @@ int32_t A_CheckInventorySprite(spritetype *s)
}
}
void app_fatal_exit(const char *msg)
{
#ifndef NETCODE_DISABLE
enet_deinitialize();
#endif
fatal_exit(msg);
}
void app_exit(int returnCode)
{
#ifndef NETCODE_DISABLE
enet_deinitialize();
#endif
if (returnCode == EXIT_SUCCESS)
{
exit(EXIT_SUCCESS);
}
else
{
Bexit(returnCode);
}
}
void G_GameExit(const char *msg)
{
......@@ -327,7 +348,7 @@ void G_GameExit(const char *msg)
Bfflush(NULL);
exit(EXIT_SUCCESS);
app_exit(EXIT_SUCCESS);
}
......@@ -714,7 +735,7 @@ static void G_ReadGLFrame(void)
// Save OpenGL screenshot with Duke3D palette
// NOTE: maybe need to move this to the engine...
static char lock;
static palette_t *frame;
......@@ -5987,7 +6008,7 @@ static void G_HandleMemErr(int32_t lineNum, const char *fileName, const char *fu
debug_break();
#endif
Bsprintf(tempbuf, "Out of memory in %s:%d (%s)\n", fileName, lineNum, funcName);
fatal_exit(tempbuf);
app_fatal_exit(tempbuf);
}
static void G_FatalEngineInitError(void)
......@@ -5998,7 +6019,7 @@ static void G_FatalEngineInitError(void)
G_Cleanup();
Bsprintf(tempbuf, "There was a problem initializing the engine: %s\n", engineerrstr);
ERRprintf("%s", tempbuf);
fatal_exit(tempbuf);
app_fatal_exit(tempbuf);
}
static void G_Startup(void)
......@@ -6304,7 +6325,7 @@ void G_DrawFrame(void)
for (auto &gv : aGameVars)
{
if ((gv.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0)
{
{
MICROPROFILE_COUNTER_SET(gv.szLabel, gv.global);
}
}
......@@ -6319,7 +6340,6 @@ int app_main(int argc, char const* const* argv)
#ifndef NETCODE_DISABLE
if (enet_initialize() != 0)
initprintf("An error occurred while initializing ENet.\n");
else atexit(enet_deinitialize);
#endif
#ifdef _WIN32
......@@ -6328,7 +6348,7 @@ int app_main(int argc, char const* const* argv)
{
if (!wm_ynbox(APPNAME, "It looks like " APPNAME " is already running.\n\n"
"Are you sure you want to start another copy?"))
return 3;
app_exit(3);
}
#endif
......@@ -6473,7 +6493,7 @@ int app_main(int argc, char const* const* argv)
if (quitevent || !startwin_run())
{
engineUnInit();
exit(EXIT_SUCCESS);
app_exit(EXIT_SUCCESS);
}
}
#endif
......@@ -6628,7 +6648,7 @@ int app_main(int argc, char const* const* argv)
if (CONTROL_Startup(controltype_keyboardandmouse, &BGetTime, TICRATE))
{
engineUnInit();
fatal_exit("There was an error initializing the CONTROL system.\n");
app_fatal_exit("There was an error initializing the CONTROL system.\n");
}
G_SetupGameButtons();
......@@ -6661,7 +6681,7 @@ int app_main(int argc, char const* const* argv)
system_getcvars();
if (quitevent) return 4;
if (quitevent) app_exit(4);
if (g_networkMode != NET_DEDICATED_SERVER && validmodecnt > 0)
{
......@@ -6954,7 +6974,7 @@ MAIN_LOOP_RESTART:
}
while (1);
return 0; // not reached (duh)
app_exit(EXIT_SUCCESS); // not reached (duh)
}
int G_DoMoveThings(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment