mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-11 16:54:42 +00:00
(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
This commit is contained in:
parent
edcc7f3cbc
commit
b7fe013793
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user