From 8aa5bb8aab317a465722c1e24b5fa1b0dcde8e69 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 15 Feb 2021 18:53:17 -0800 Subject: [PATCH] Clean up all program close paths to use VVV_exit() Wow, there are a lot of these. All of these exit paths now use VVV_exit() instead, which attempts to save unlock.vvv and settings.vvv, and also frees all resources so Valgrind is happy. This is a good thing, because previously unlock.vvv/settings.vvv wouldn't be written to if we decided to bail for a given reason. --- desktop_version/src/BinaryBlob.cpp | 4 ++-- desktop_version/src/Graphics.cpp | 6 +++--- desktop_version/src/Script.cpp | 6 ++---- desktop_version/src/main.cpp | 9 +++++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 83ebaa76..0850e4bd 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -3,8 +3,8 @@ #include /* FIXME: Abstract to FileSystemUtils! */ #include #include -#include +#include "Exit.h" #include "UtilityClass.h" binaryBlob::binaryBlob() @@ -113,7 +113,7 @@ bool binaryBlob::unPackBinary(const char* name) m_memblocks[i] = (char*) SDL_malloc(m_headers[i].size); if (m_memblocks[i] == NULL) { - exit(1); /* Oh god we're out of memory, just bail */ + VVV_exit(1); /* Oh god we're out of memory, just bail */ } PHYSFS_readBytes(handle, m_memblocks[i], m_headers[i].size); offset += m_headers[i].size; diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 369d75f4..0e681376 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -2,11 +2,11 @@ #include "Graphics.h" #include -#include #include #include "editor.h" #include "Entity.h" +#include "Exit.h" #include "FileSystemUtils.h" #include "Map.h" #include "Music.h" @@ -254,7 +254,7 @@ int Graphics::font_idx(uint32_t ch) if (iter == font_positions.end()) { puts("font.txt missing fallback character!"); - exit(1); + VVV_exit(1); } } return iter->second; @@ -322,7 +322,7 @@ void Graphics::updatetitlecolours() NULL \ ); \ \ - exit(1); \ + VVV_exit(1); \ } #define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \ diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 5f6263bb..622acc7d 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -6,6 +6,7 @@ #include "editor.h" #include "Entity.h" #include "Enums.h" +#include "Exit.h" #include "Graphics.h" #include "KeyPoll.h" #include "Map.h" @@ -3396,10 +3397,7 @@ void scriptclass::startgamemode( int t ) } #endif case 100: - game.savestatsandsettings(); - - SDL_Quit(); - exit(0); + VVV_exit(0); break; } } diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 7b272625..99015a6d 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -4,6 +4,7 @@ #include "editor.h" #include "Enums.h" #include "Entity.h" +#include "Exit.h" #include "FileSystemUtils.h" #include "Game.h" #include "Graphics.h" @@ -93,7 +94,7 @@ int main(int argc, char *argv[]) else \ { \ printf("%s option requires one argument.\n", argv[i]); \ - return 1; \ + VVV_exit(1); \ } if (ARG("-renderer")) @@ -156,14 +157,14 @@ int main(int argc, char *argv[]) else { printf("Error: invalid option: %s\n", argv[i]); - return 1; + VVV_exit(1); } } if(!FILESYSTEM_init(argv[0], baseDir, assetsPath)) { puts("Unable to initialize filesystem!"); - return 1; + VVV_exit(1); } SDL_Init( @@ -311,7 +312,7 @@ int main(int argc, char *argv[]) ed.ListOfMetaData.push_back(meta); } else { printf("Level not found\n"); - return 1; + VVV_exit(1); } }