From f5053cee7e45f582d4dede4025cfaa0a1bd39b96 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 10 Jan 2010 14:30:32 +0000 Subject: (svn r18770) -Fix-ish: don't allow the memory saveload format to be chosen for savegames; it's utterly useless to make a snapshot in memory and then throw that away without doing anything with it. --- src/saveload/saveload.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/saveload') diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 1633e853e..8d0a09a81 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1599,7 +1599,6 @@ struct SaveLoadFormat { }; static const SaveLoadFormat _saveload_formats[] = { - {"memory", 0, NULL, NULL, NULL, InitMem, WriteMem, UnInitMem}, #if defined(WITH_LZO) {"lzo", TO_BE32X('OTTD'), InitLZO, ReadLZO, UninitLZO, InitLZO, WriteLZO, UninitLZO}, #else @@ -1737,7 +1736,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded) fmt->uninit_write(); if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk"); - GetSavegameFormat("memory")->uninit_write(); // clean the memorypool + UnInitMem(); fclose(_sl.fh); if (threaded) SetAsyncSaveFinish(SaveFileDone); @@ -1786,7 +1785,6 @@ void WaitTillSaved() SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded) { uint32 hdr[2]; - const SaveLoadFormat *fmt; /* An instance of saving is already active, so don't go saving again */ if (_ts.saveinprogress && mode == SL_SAVE) { @@ -1835,14 +1833,10 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo * to write it to file, either in threaded mode if possible, or single-threaded */ if (mode == SL_SAVE) { // SAVE game DEBUG(desync, 1, "save: %s\n", filename); - fmt = GetSavegameFormat("memory"); // write to memory - _sl.write_bytes = fmt->writer; - _sl.excpt_uninit = fmt->uninit_write; - if (!fmt->init_write()) { - DEBUG(sl, 0, "Initializing writer '%s' failed.", fmt->name); - return AbortSaveLoad(); - } + _sl.write_bytes = WriteMem; + _sl.excpt_uninit = UnInitMem; + InitMem(); _sl_version = SAVEGAME_VERSION; @@ -1869,7 +1863,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo if (fread(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); /* see if we have any loader for this type. */ - for (fmt = _saveload_formats; ; fmt++) { + const SaveLoadFormat *fmt = _saveload_formats; + for (;;) { /* No loader found, treat as version 0 and use LZO format */ if (fmt == endof(_saveload_formats)) { DEBUG(sl, 0, "Unknown savegame type, trying to load it as the buggy format"); @@ -1896,6 +1891,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo if (_sl_version > SAVEGAME_VERSION) SlError(STR_GAME_SAVELOAD_ERROR_TOO_NEW_SAVEGAME); break; } + + fmt++; } _sl.read_bytes = fmt->reader; -- cgit v1.2.3-70-g09d2