mirror of https://github.com/OpenTTD/OpenTTD
(svn r12707) -Fix: do not crash very hard on unrecognised savegames, just go back to the intro menu instead.
parent
12188e7a5d
commit
be7e36e0b9
|
@ -76,13 +76,24 @@ static struct {
|
||||||
|
|
||||||
enum NeedLengthValues {NL_NONE = 0, NL_WANTLENGTH = 1, NL_CALCLENGTH = 2};
|
enum NeedLengthValues {NL_NONE = 0, NL_WANTLENGTH = 1, NL_CALCLENGTH = 2};
|
||||||
|
|
||||||
|
/** Error handler, calls longjmp to simulate an exception.
|
||||||
|
* @todo this was used to have a central place to handle errors, but it is
|
||||||
|
* pretty ugly, and seriously interferes with any multithreaded approaches */
|
||||||
|
static void NORETURN SlError(StringID string, const char *extra_msg = NULL)
|
||||||
|
{
|
||||||
|
_sl.error_str = string;
|
||||||
|
free(_sl.extra_msg);
|
||||||
|
_sl.extra_msg = (extra_msg == NULL) ? NULL : strdup(extra_msg);
|
||||||
|
throw std::exception();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill the input buffer by reading from the file with the given reader
|
* Fill the input buffer by reading from the file with the given reader
|
||||||
*/
|
*/
|
||||||
static void SlReadFill()
|
static void SlReadFill()
|
||||||
{
|
{
|
||||||
uint len = _sl.read_bytes();
|
uint len = _sl.read_bytes();
|
||||||
assert(len != 0);
|
if (len == 0) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected end of chunk");
|
||||||
|
|
||||||
_sl.bufp = _sl.buf;
|
_sl.bufp = _sl.buf;
|
||||||
_sl.bufe = _sl.buf + len;
|
_sl.bufe = _sl.buf + len;
|
||||||
|
@ -137,17 +148,6 @@ static void SlWriteFill()
|
||||||
_sl.bufe = _sl.buf + _sl.bufsize;
|
_sl.bufe = _sl.buf + _sl.bufsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Error handler, calls longjmp to simulate an exception.
|
|
||||||
* @todo this was used to have a central place to handle errors, but it is
|
|
||||||
* pretty ugly, and seriously interferes with any multithreaded approaches */
|
|
||||||
static void NORETURN SlError(StringID string, const char *extra_msg = NULL)
|
|
||||||
{
|
|
||||||
_sl.error_str = string;
|
|
||||||
free(_sl.extra_msg);
|
|
||||||
_sl.extra_msg = (extra_msg == NULL) ? NULL : strdup(extra_msg);
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Read in a single byte from file. If the temporary buffer is full,
|
/** Read in a single byte from file. If the temporary buffer is full,
|
||||||
* flush it to its final destination
|
* flush it to its final destination
|
||||||
* @return return the read byte from file
|
* @return return the read byte from file
|
||||||
|
@ -1524,7 +1524,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||||
uint i;
|
uint i;
|
||||||
uint count = 1 << Savegame_POOL_BLOCK_SIZE_BITS;
|
uint count = 1 << Savegame_POOL_BLOCK_SIZE_BITS;
|
||||||
|
|
||||||
assert(_ts.count == _sl.offs_base);
|
if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk");
|
||||||
for (i = 0; i != _Savegame_pool.GetBlockCount() - 1; i++) {
|
for (i = 0; i != _Savegame_pool.GetBlockCount() - 1; i++) {
|
||||||
_sl.buf = _Savegame_pool.blocks[i];
|
_sl.buf = _Savegame_pool.blocks[i];
|
||||||
fmt->writer(count);
|
fmt->writer(count);
|
||||||
|
@ -1537,7 +1537,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt->uninit_write();
|
fmt->uninit_write();
|
||||||
assert(_ts.count == _sl.offs_base);
|
if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk");
|
||||||
GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
|
GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
|
||||||
fclose(_sl.fh);
|
fclose(_sl.fh);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue