Commit 9c036c8f authored by coppro's avatar coppro

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.
parent 0c3250cf
......@@ -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;
}
......
......@@ -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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment