From 0c25b1bc0a1ef27bf47b2ea863fbd8a34dbdb32e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Jun 2000 09:12:42 +0000 Subject: [PATCH] reentrancy fix (extremely ugly, will have to do better soon) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7624 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fontmap.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/common/fontmap.cpp b/src/common/fontmap.cpp index 89dca5c3f6..1d0676ef20 100644 --- a/src/common/fontmap.cpp +++ b/src/common/fontmap.cpp @@ -553,6 +553,32 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, const wxString& facename, bool interactive) { +#if wxUSE_GUI + // we need a flag to prevent infinite recursion which happens, for + // example, when GetAltForEncoding() is called from an OnPaint() handler: + // in this case, wxYield() which is called from wxMessageBox() we use here + // will lead to another call of OnPaint() and hence to another call of + // GetAltForEncoding() - and it is impossible to catch this from the user + // code because we are called from wxFont ctor implicitly. + + // assume we're always called from the main thread, so that it is safe to + // use a static var + static bool s_inGetAltForEncoding = FALSE; + + if ( interactive && s_inGetAltForEncoding ) + return FALSE; + + class ReentrancyBlocker + { + public: + ReentrancyBlocker(bool& b) : m_b(b) { m_b = TRUE; } + ~ReentrancyBlocker() { m_b = FALSE; } + + private: + bool& m_b; + } blocker(s_inGetAltForEncoding); +#endif // wxUSE_GUI + wxCHECK_MSG( info, FALSE, wxT("bad pointer in GetAltForEncoding") ); info->facename = facename;