From f2055044f9fbac5bf54bb9534644c43979c0a727 Mon Sep 17 00:00:00 2001 From: coppro Date: Sat, 21 Jun 2008 05:02:46 +0000 Subject: [PATCH] Changed from a critical section to a mutex for error handling. show_pending_errors() was being called over and over again from the GUI update system - somehow it managed to have a single thread in two places at once. Also tried recursive mutex, resulted in infinite dialogs until an out-of-memory crash. Also, minor conversion fix. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@998 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/script/value.cpp | 2 +- src/util/error.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/script/value.cpp b/src/script/value.cpp index 8db071e8..8063703e 100644 --- a/src/script/value.cpp +++ b/src/script/value.cpp @@ -28,7 +28,7 @@ ScriptValueP ScriptValue::next() { throw Intern ScriptValueP ScriptValue::makeIterator(const ScriptValueP&) const { return delayError(_ERROR_2_("can't convert", typeName(), _TYPE_("collection"))); } int ScriptValue::itemCount() const { throw ScriptError(_ERROR_2_("can't convert", typeName(), _TYPE_("collection"))); } CompareWhat ScriptValue::compareAs(String& compare_str, void const*& compare_ptr) const { - compare_str = (String)(*this); + compare_str = toString(); return COMPARE_AS_STRING; } diff --git a/src/util/error.cpp b/src/util/error.cpp index 01a579e7..f2b8bf3e 100644 --- a/src/util/error.cpp +++ b/src/util/error.cpp @@ -61,7 +61,7 @@ vector previous_warnings; String pending_errors; String pending_warnings; DECLARE_TYPEOF_COLLECTION(String); -wxCriticalSection crit_error_handling; +wxMutex crit_error_handling; void show_pending_errors(); void show_pending_warnings(); @@ -69,7 +69,7 @@ void show_pending_warnings(); void handle_error(const String& e, bool allow_duplicate = true, bool now = true) { { // Thread safety - wxCriticalSectionLocker lock(crit_error_handling); + wxMutexLocker lock(crit_error_handling); // Check duplicates if (!allow_duplicate) { FOR_EACH(pe, previous_errors) { @@ -95,7 +95,7 @@ void handle_error(const Error& e, bool allow_duplicate, bool now) { void handle_warning(const String& w, bool now) { { // Check duplicates - wxCriticalSectionLocker lock(crit_error_handling); + wxMutexLocker lock(crit_error_handling); // Check duplicates FOR_EACH(pw, previous_warnings) { if (w == pw) return; @@ -119,17 +119,21 @@ void handle_pending_errors() { void show_pending_errors() { assert(wxThread::IsMain()); - wxCriticalSectionLocker lock(crit_error_handling); + if (crit_error_handling.TryLock() != wxMUTEX_NO_ERROR) + return; if (!pending_errors.empty()) { wxMessageBox(pending_errors, _("Error"), wxOK | wxICON_ERROR); pending_errors.clear(); } + crit_error_handling.Unlock(); } void show_pending_warnings() { assert(wxThread::IsMain()); - wxCriticalSectionLocker lock(crit_error_handling); + if (crit_error_handling.TryLock() != wxMUTEX_NO_ERROR) + return; if (!pending_warnings.empty()) { wxMessageBox(pending_warnings, _("Warning"), wxOK | wxICON_EXCLAMATION); pending_warnings.clear(); } + crit_error_handling.Unlock(); }