mirror of https://github.com/OpenTTD/OpenTTD
Change: Use SlErrorCorrupt() on pool index error when loading a savegame, instead of terminating. (#7219)
parent
830ed6be61
commit
c0c8fb25fb
|
@ -152,18 +152,20 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_t size)
|
||||||
* @param size size of item
|
* @param size size of item
|
||||||
* @param index index of item
|
* @param index index of item
|
||||||
* @return pointer to allocated item
|
* @return pointer to allocated item
|
||||||
* @note usererror() on failure! (index out of range or already used)
|
* @note SlErrorCorruptFmt() on failure! (index out of range or already used)
|
||||||
*/
|
*/
|
||||||
DEFINE_POOL_METHOD(void *)::GetNew(size_t size, size_t index)
|
DEFINE_POOL_METHOD(void *)::GetNew(size_t size, size_t index)
|
||||||
{
|
{
|
||||||
|
extern void NORETURN SlErrorCorruptFmt(const char *format, ...);
|
||||||
|
|
||||||
if (index >= Tmax_size) {
|
if (index >= Tmax_size) {
|
||||||
usererror("failed loading savegame: %s index " PRINTF_SIZE " out of range (" PRINTF_SIZE ")", this->name, index, Tmax_size);
|
SlErrorCorruptFmt("%s index " PRINTF_SIZE " out of range (" PRINTF_SIZE ")", this->name, index, Tmax_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= this->size) this->ResizeFor(index);
|
if (index >= this->size) this->ResizeFor(index);
|
||||||
|
|
||||||
if (this->data[index] != NULL) {
|
if (this->data[index] != NULL) {
|
||||||
usererror("failed loading savegame: %s index " PRINTF_SIZE " already in use", this->name, index);
|
SlErrorCorruptFmt("%s index " PRINTF_SIZE " already in use", this->name, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->AllocateItem(size, index);
|
return this->AllocateItem(size, index);
|
||||||
|
|
|
@ -350,6 +350,25 @@ void NORETURN SlErrorCorrupt(const char *msg)
|
||||||
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
|
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issue an SlErrorCorrupt with a format string.
|
||||||
|
* @param format format string
|
||||||
|
* @param ... arguments to format string
|
||||||
|
* @note This function does never return as it throws an exception to
|
||||||
|
* break out of all the saveload code.
|
||||||
|
*/
|
||||||
|
void NORETURN SlErrorCorruptFmt(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char msg[256];
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
vseprintf(msg, lastof(msg), format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
SlErrorCorrupt(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef void (*AsyncSaveFinishProc)(); ///< Callback for when the savegame loading is finished.
|
typedef void (*AsyncSaveFinishProc)(); ///< Callback for when the savegame loading is finished.
|
||||||
static AsyncSaveFinishProc _async_save_finish = NULL; ///< Callback to call when the savegame loading is finished.
|
static AsyncSaveFinishProc _async_save_finish = NULL; ///< Callback to call when the savegame loading is finished.
|
||||||
|
|
|
@ -836,6 +836,7 @@ void SlObject(void *object, const SaveLoad *sld);
|
||||||
bool SlObjectMember(void *object, const SaveLoad *sld);
|
bool SlObjectMember(void *object, const SaveLoad *sld);
|
||||||
void NORETURN SlError(StringID string, const char *extra_msg = NULL);
|
void NORETURN SlError(StringID string, const char *extra_msg = NULL);
|
||||||
void NORETURN SlErrorCorrupt(const char *msg);
|
void NORETURN SlErrorCorrupt(const char *msg);
|
||||||
|
void NORETURN SlErrorCorruptFmt(const char *format, ...);
|
||||||
|
|
||||||
bool SaveloadCrashWithMissingNewGRFs();
|
bool SaveloadCrashWithMissingNewGRFs();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue