summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-07-08 11:50:42 +0000
committerrubidium <rubidium@openttd.org>2010-07-08 11:50:42 +0000
commitb7fe01379389ea536e01fcbcc3038b9c77901da6 (patch)
treea877a14dc5957e05f7f8a2853724794e307b7145 /src/saveload
parentedcc7f3cbcd18763d5593d1ca27a8b688ea13fc9 (diff)
downloadopenttd-b7fe01379389ea536e01fcbcc3038b9c77901da6.tar.xz
(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
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/saveload.cpp18
1 files changed, 9 insertions, 9 deletions
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