From 3d5d28d4ec50f285d5f8508aaa28d7f246f86224 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 12 Nov 2019 19:48:12 +0100 Subject: [PATCH] Fix calling init_cleanup on shutdown - Fixes saving audio volume - Fix memeory leak warnings Thanks to @de4me for pointing this out --- Source/appfat.cpp | 2 -- Source/diablo.cpp | 5 ++++- Source/init.cpp | 5 +---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index bd3c388ff..6bd9a99f4 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -20,8 +20,6 @@ void __cdecl app_fatal(const char *pszFmt, ...) va_end(va); - dx_cleanup(); - init_cleanup(); exit(1); } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index ff1d5b3f1..0c4f022ba 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -254,11 +254,13 @@ void diablo_init(LPSTR lpCmdLine) SFileEnableDirectAccess(TRUE); init_archives(); + atexit(init_cleanup); UiInitialize(); #ifdef SPAWN UiSetSpawned(TRUE); #endif + atexit(UiDestroy); ReadOnlyTest(); @@ -269,7 +271,9 @@ void diablo_init(LPSTR lpCmdLine) diablo_parse_flags(lpCmdLine); snd_init(NULL); + atexit(sound_cleanup); sound_init(); + atexit(effects_cleanup_sfx); } void diablo_splash() @@ -294,7 +298,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi diablo_init(lpCmdLine); diablo_splash(); mainmenu_loop(); - UiDestroy(); return 0; } diff --git a/Source/init.cpp b/Source/init.cpp index 86f44d9ab..93eb36e9e 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -39,11 +39,7 @@ void init_cleanup() hellfire_mpq = NULL; } - UiDestroy(); - effects_cleanup_sfx(); - sound_cleanup(); NetClose(); - dx_cleanup(); } void init_create_window() @@ -51,6 +47,7 @@ void init_create_window() if (!SpawnWindow(PROJECT_NAME, SCREEN_WIDTH, SCREEN_HEIGHT)) app_fatal("Unable to create main window"); dx_init(NULL); + atexit(dx_cleanup); gbActive = true; gpBufStart = &gpBuffer[BUFFER_WIDTH * SCREEN_Y]; gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)];