mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Explicitly prevent writing to saves if filesystem is not init
Another cause of #870 is d0ffafe117
, as a
bisect tells me. What that commit did is remove screenbuffer as a
pointer, since it's a statically-allocated object that _should_ always
exist, and it removed the `screenbuffer == NULL` guards in savestats()
and savesettings(). Unfortunately, those guards did something very
important - namely, they prevented writing to the save files when the
filesystem wasn't initialized. But that wasn't made clear, because it
seemed like the point of those guards was to prevent dereferencing NULL.
So instead, explicitly make it clear that
FILESYSTEM_saveTiXml2Document() needs to fail if the filesystem isn't
initialized. I've done this by adding an isInit bool to
FileSystemUtils.cpp.
This commit is contained in:
parent
997363ce56
commit
75ee657612
1 changed files with 11 additions and 0 deletions
|
@ -34,6 +34,8 @@ static int mkdir(char* path, int mode)
|
||||||
#define MAX_PATH PATH_MAX
|
#define MAX_PATH PATH_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool isInit = false;
|
||||||
|
|
||||||
static const char* pathSep = NULL;
|
static const char* pathSep = NULL;
|
||||||
static char* basePath = NULL;
|
static char* basePath = NULL;
|
||||||
static char saveDir[MAX_PATH] = {'\0'};
|
static char saveDir[MAX_PATH] = {'\0'};
|
||||||
|
@ -179,6 +181,8 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
|
||||||
{
|
{
|
||||||
vlog_info("gamecontrollerdb.txt not found!");
|
vlog_info("gamecontrollerdb.txt not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInit = true;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +202,7 @@ void FILESYSTEM_deinit(void)
|
||||||
}
|
}
|
||||||
SDL_free(basePath);
|
SDL_free(basePath);
|
||||||
basePath = NULL;
|
basePath = NULL;
|
||||||
|
isInit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *FILESYSTEM_getUserSaveDirectory(void)
|
char *FILESYSTEM_getUserSaveDirectory(void)
|
||||||
|
@ -910,6 +915,12 @@ fail:
|
||||||
|
|
||||||
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc, bool sync /*= true*/)
|
bool FILESYSTEM_saveTiXml2Document(const char *name, tinyxml2::XMLDocument& doc, bool sync /*= true*/)
|
||||||
{
|
{
|
||||||
|
if (!isInit)
|
||||||
|
{
|
||||||
|
vlog_warn("Filesystem not initialized! Not writing just to be safe.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* XMLDocument.SaveFile doesn't account for Unicode paths, PHYSFS does */
|
/* XMLDocument.SaveFile doesn't account for Unicode paths, PHYSFS does */
|
||||||
tinyxml2::XMLPrinter printer;
|
tinyxml2::XMLPrinter printer;
|
||||||
doc.Print(&printer);
|
doc.Print(&printer);
|
||||||
|
|
Loading…
Reference in a new issue