From b7fe01379389ea536e01fcbcc3038b9c77901da6 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 8 Jul 2010 11:50:42 +0000 Subject: (svn r20087) -Fix [FS#3876, FS#3887, FS#3920, FS#3923]: if after loading a savegame (including intro game) one tried to save a game (including autosave) and that failed (very) early on because it couldn't open the file for writing all pointers would be converted to NULLs which then causes corrupted game states --- src/saveload/saveload.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/saveload') diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index e3a588795..19883c96e 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1961,6 +1961,15 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo if (mode == SL_LOAD_CHECK) _load_check_data.checkable = true; _sl.excpt_uninit = NULL; + _sl.bufe = _sl.bufp = NULL; + _sl.offs_base = 0; + switch (mode) { + case SL_LOAD_CHECK: _sl.action = SLA_LOAD_CHECK; break; + case SL_LOAD: _sl.action = SLA_LOAD; break; + case SL_SAVE: _sl.action = SLA_SAVE; break; + default: NOT_REACHED(); + } + try { _sl.fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb); @@ -1972,15 +1981,6 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); } - _sl.bufe = _sl.bufp = NULL; - _sl.offs_base = 0; - switch (mode) { - case SL_LOAD_CHECK: _sl.action = SLA_LOAD_CHECK; break; - case SL_LOAD: _sl.action = SLA_LOAD; break; - case SL_SAVE: _sl.action = SLA_SAVE; break; - default: NOT_REACHED(); - } - /* General tactic is to first save the game to memory, then use an available writer * to write it to file, either in threaded mode if possible, or single-threaded */ if (mode == SL_SAVE) { // SAVE game -- cgit v1.2.3-70-g09d2