1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2025-01-10 02:49:45 +01:00

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.
This commit is contained in:
Misa 2021-02-15 18:53:17 -08:00 committed by Ethan Lee
parent de1e773b7f
commit 8aa5bb8aab
4 changed files with 12 additions and 13 deletions

View file

@ -3,8 +3,8 @@
#include <physfs.h> /* FIXME: Abstract to FileSystemUtils! */ #include <physfs.h> /* FIXME: Abstract to FileSystemUtils! */
#include <SDL.h> #include <SDL.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "Exit.h"
#include "UtilityClass.h" #include "UtilityClass.h"
binaryBlob::binaryBlob() binaryBlob::binaryBlob()
@ -113,7 +113,7 @@ bool binaryBlob::unPackBinary(const char* name)
m_memblocks[i] = (char*) SDL_malloc(m_headers[i].size); m_memblocks[i] = (char*) SDL_malloc(m_headers[i].size);
if (m_memblocks[i] == NULL) 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); PHYSFS_readBytes(handle, m_memblocks[i], m_headers[i].size);
offset += m_headers[i].size; offset += m_headers[i].size;

View file

@ -2,11 +2,11 @@
#include "Graphics.h" #include "Graphics.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <utf8/unchecked.h> #include <utf8/unchecked.h>
#include "editor.h" #include "editor.h"
#include "Entity.h" #include "Entity.h"
#include "Exit.h"
#include "FileSystemUtils.h" #include "FileSystemUtils.h"
#include "Map.h" #include "Map.h"
#include "Music.h" #include "Music.h"
@ -254,7 +254,7 @@ int Graphics::font_idx(uint32_t ch)
if (iter == font_positions.end()) if (iter == font_positions.end())
{ {
puts("font.txt missing fallback character!"); puts("font.txt missing fallback character!");
exit(1); VVV_exit(1);
} }
} }
return iter->second; return iter->second;
@ -322,7 +322,7 @@ void Graphics::updatetitlecolours()
NULL \ NULL \
); \ ); \
\ \
exit(1); \ VVV_exit(1); \
} }
#define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \ #define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \

View file

@ -6,6 +6,7 @@
#include "editor.h" #include "editor.h"
#include "Entity.h" #include "Entity.h"
#include "Enums.h" #include "Enums.h"
#include "Exit.h"
#include "Graphics.h" #include "Graphics.h"
#include "KeyPoll.h" #include "KeyPoll.h"
#include "Map.h" #include "Map.h"
@ -3396,10 +3397,7 @@ void scriptclass::startgamemode( int t )
} }
#endif #endif
case 100: case 100:
game.savestatsandsettings(); VVV_exit(0);
SDL_Quit();
exit(0);
break; break;
} }
} }

View file

@ -4,6 +4,7 @@
#include "editor.h" #include "editor.h"
#include "Enums.h" #include "Enums.h"
#include "Entity.h" #include "Entity.h"
#include "Exit.h"
#include "FileSystemUtils.h" #include "FileSystemUtils.h"
#include "Game.h" #include "Game.h"
#include "Graphics.h" #include "Graphics.h"
@ -93,7 +94,7 @@ int main(int argc, char *argv[])
else \ else \
{ \ { \
printf("%s option requires one argument.\n", argv[i]); \ printf("%s option requires one argument.\n", argv[i]); \
return 1; \ VVV_exit(1); \
} }
if (ARG("-renderer")) if (ARG("-renderer"))
@ -156,14 +157,14 @@ int main(int argc, char *argv[])
else else
{ {
printf("Error: invalid option: %s\n", argv[i]); printf("Error: invalid option: %s\n", argv[i]);
return 1; VVV_exit(1);
} }
} }
if(!FILESYSTEM_init(argv[0], baseDir, assetsPath)) if(!FILESYSTEM_init(argv[0], baseDir, assetsPath))
{ {
puts("Unable to initialize filesystem!"); puts("Unable to initialize filesystem!");
return 1; VVV_exit(1);
} }
SDL_Init( SDL_Init(
@ -311,7 +312,7 @@ int main(int argc, char *argv[])
ed.ListOfMetaData.push_back(meta); ed.ListOfMetaData.push_back(meta);
} else { } else {
printf("Level not found\n"); printf("Level not found\n");
return 1; VVV_exit(1);
} }
} }