diff options
author | frosch <frosch@openttd.org> | 2010-06-05 12:16:12 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-06-05 12:16:12 +0000 |
commit | 1d3adb2b66989630b2a3c201ac1210a886d41a51 (patch) | |
tree | c7c2c22646cfdeb1312455bfd9d59674b7ff96be /src/core | |
parent | 406c2a986571ce594f491c0fde225b89f14ac8c3 (diff) | |
download | openttd-1d3adb2b66989630b2a3c201ac1210a886d41a51.tar.xz |
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/backup_type.hpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/core/backup_type.hpp b/src/core/backup_type.hpp index 90b48c2a8..60799170f 100644 --- a/src/core/backup_type.hpp +++ b/src/core/backup_type.hpp @@ -12,6 +12,8 @@ #ifndef BACKUP_TYPE_HPP #define BACKUP_TYPE_HPP +#include "../debug.h" + /** * Class to backup a specific variable and restore it later. * The variable is not restored automatically, but assertions make sure it is restored. @@ -22,16 +24,20 @@ struct Backup { /** * Backup variable. * @param original Variable to backup. + * @param file Filename for debug output. Use FILE_LINE macro. + * @param line Linenumber for debug output. Use FILE_LINE macro. */ - Backup(T &original) : original(original), valid(true), original_value(original) {} + Backup(T &original, const char * const file, const int line) : original(original), valid(true), original_value(original), file(file), line(line) {} /** * Backup variable and switch to new value. * @param original Variable to backup. * @param new_value New value for variable. + * @param file Filename for debug output. Use FILE_LINE macro. + * @param line Linenumber for debug output. Use FILE_LINE macro. */ template <typename U> - Backup(T &original, const U &new_value) : original(original), valid(true), original_value(original) + Backup(T &original, const U &new_value, const char * const file, const int line) : original(original), valid(true), original_value(original), file(file), line(line) { /* Note: We use a separate typename U, so type conversions are handled by assignment operator. */ original = new_value; @@ -43,7 +49,13 @@ struct Backup { ~Backup() { /* Check whether restoration was done */ - assert(!this->valid); + if (this->valid) + { + /* We cannot assert here, as missing restoration is 'normal' when exceptions are thrown. + * Exceptions are especially used to abort world generation. */ + DEBUG(misc, 0, "%s:%d: Backupped value was not restored!", this->file, this->line); + this->Restore(); + } } /** @@ -129,6 +141,9 @@ private: T &original; bool valid; T original_value; + + const char * const file; + const int line; }; #endif /* BACKUP_TYPE_HPP */ |