summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-11-25 22:22:32 +0000
committerrubidium <rubidium@openttd.org>2013-11-25 22:22:32 +0000
commit77e5b1e3b26320e7d66a3835424c95fcb77e43bb (patch)
treed7aca63fcb699043679d240f8cd05fc8407c8d84 /src/saveload
parentd2ffba07bb747deaaae2fc58b3c71328a362d928 (diff)
downloadopenttd-77e5b1e3b26320e7d66a3835424c95fcb77e43bb.tar.xz
(svn r26115) -Fix: AfterLoadGame can throw an exception; from the old savegame load section this wouldn't be caught
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/saveload.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index dc63abe5b..8bcf57119 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2720,36 +2720,36 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
}
WaitTillSaved();
- /* Load a TTDLX or TTDPatch game */
- if (mode == SL_OLD_LOAD) {
- InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
-
- /* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
- * and if so a new NewGRF list will be made in LoadOldSaveGame.
- * Note: this is done here because AfterLoadGame is also called
- * for OTTD savegames which have their own NewGRF logic. */
- ClearGRFConfigList(&_grfconfig);
- GamelogReset();
- if (!LoadOldSaveGame(filename)) return SL_REINIT;
- _sl_version = 0;
- _sl_minor_version = 0;
- GamelogStartAction(GLAT_LOAD);
- if (!AfterLoadGame()) {
+ try {
+ /* Load a TTDLX or TTDPatch game */
+ if (mode == SL_OLD_LOAD) {
+ InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
+
+ /* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
+ * and if so a new NewGRF list will be made in LoadOldSaveGame.
+ * Note: this is done here because AfterLoadGame is also called
+ * for OTTD savegames which have their own NewGRF logic. */
+ ClearGRFConfigList(&_grfconfig);
+ GamelogReset();
+ if (!LoadOldSaveGame(filename)) return SL_REINIT;
+ _sl_version = 0;
+ _sl_minor_version = 0;
+ GamelogStartAction(GLAT_LOAD);
+ if (!AfterLoadGame()) {
+ GamelogStopAction();
+ return SL_REINIT;
+ }
GamelogStopAction();
- return SL_REINIT;
+ return SL_OK;
}
- GamelogStopAction();
- return SL_OK;
- }
- 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();
- }
+ 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 {
FILE *fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
/* Make it a little easier to load savegames from the console */
@@ -2779,7 +2779,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
if (mode != SL_LOAD_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
/* A saver/loader exception!! reinitialize all variables to prevent crash! */
- return (mode == SL_LOAD) ? SL_REINIT : SL_ERROR;
+ return (mode == SL_LOAD || mode == SL_OLD_LOAD) ? SL_REINIT : SL_ERROR;
}
}