From 1d3adb2b66989630b2a3c201ac1210a886d41a51 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 5 Jun 2010 12:16:12 +0000 Subject: (svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation. --- src/core/backup_type.hpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/core') 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 - 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 */ -- cgit v1.2.3-70-g09d2