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
This commit is contained in:
coppro
2008-06-21 05:02:46 +00:00
parent 158ecf67ad
commit f2055044f9
2 changed files with 10 additions and 6 deletions
+9 -5
View File
@@ -61,7 +61,7 @@ vector<String> 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();
}