From: Václav Slavík Date: Sun, 9 Nov 2003 12:09:13 +0000 (+0000) Subject: prevent deadlock in wxCSConv::DoCreate if it fails for wxConvLocal -- ugly but works X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a58d4f4d49a00dc9059fd0f7129d5735d21482ef prevent deadlock in wxCSConv::DoCreate if it fails for wxConvLocal -- ugly but works git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24491 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index ffd70ff003..7c86dd16e3 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -1417,8 +1417,19 @@ wxMBConv *wxCSConv::DoCreate() const } #endif // wxUSE_FONTMAP - wxLogError(_("Cannot convert from the charset '%s'!"), - m_name ? m_name + // NB: This is a hack to prevent deadlock. What could otherwise happen + // in Unicode build: wxConvLocal creation ends up being here + // because of some failure and logs the error. But wxLog will try to + // attach timestamp, for which it will need wxConvLocal (to convert + // time to char* and then wchar_t*), but that fails, tries to log + // error, but wxLog has a (already locked) critical section that + // guards static buffer. + static bool alreadyLoggingError = false; + if (!alreadyLoggingError) + { + alreadyLoggingError = true; + wxLogError(_("Cannot convert from the charset '%s'!"), + m_name ? m_name : #if wxUSE_FONTMAP wxFontMapper::GetEncodingDescription(m_encoding).c_str() @@ -1426,6 +1437,8 @@ wxMBConv *wxCSConv::DoCreate() const wxString::Format(_("encoding %s"), m_encoding).c_str() #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP ); + alreadyLoggingError = false; + } return NULL; }