X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de4de64f1c693011913c1f59d4cb00a09c6ebd28..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/common/appbase.cpp diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 8dec8e8a92..0892aab62d 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -68,8 +68,11 @@ #endif // __WXMAC__ #ifdef __WXDEBUG__ - #ifdef wxUSE_STACKWALKER + #if wxUSE_STACKWALKER #include "wx/stackwalk.h" + #ifdef __WXMSW__ + #include "wx/msw/debughlp.h" + #endif #endif // wxUSE_STACKWALKER #endif // __WXDEBUG__ @@ -139,14 +142,6 @@ wxAppConsole::~wxAppConsole() bool wxAppConsole::Initialize(int& argc, wxChar **argv) { -#if wxUSE_LOG - // If some code logged something before wxApp instance was created, - // wxLogStderr was set as the target. Undo it here by destroying the - // current target. It will be re-created next time logging is needed, but - // this time wxAppTraits will be used: - delete wxLog::SetActiveTarget(NULL); -#endif // wxUSE_LOG - // remember the command line arguments this->argc = argc; this->argv = argv; @@ -272,6 +267,7 @@ void wxAppConsole::ProcessPendingEvents() #if wxUSE_THREADS if ( !wxPendingEventsLocker ) return; +#endif // ensure that we're the only thread to modify the pending events list wxENTER_CRIT_SECT( *wxPendingEventsLocker ); @@ -281,7 +277,6 @@ void wxAppConsole::ProcessPendingEvents() wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); return; } -#endif // iterate until the list becomes empty wxList::compatibility_iterator node = wxPendingEvents->GetFirst(); @@ -290,24 +285,18 @@ void wxAppConsole::ProcessPendingEvents() wxEvtHandler *handler = (wxEvtHandler *)node->GetData(); wxPendingEvents->Erase(node); -#if wxUSE_THREADS // In ProcessPendingEvents(), new handlers might be add // and we can safely leave the critical section here. wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); -#endif handler->ProcessPendingEvents(); -#if wxUSE_THREADS wxENTER_CRIT_SECT( *wxPendingEventsLocker ); -#endif node = wxPendingEvents->GetFirst(); } -#if wxUSE_THREADS wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); -#endif } int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event)) @@ -713,35 +702,17 @@ bool DoShowAssertDialog(const wxString& msg) return false; } -// show the assert modal dialog -static -void ShowAssertDialog(const wxChar *szFile, - int nLine, - const wxChar *szCond, - const wxChar *szMsg, - wxAppTraits *traits) +#if wxUSE_STACKWALKER +static wxString GetAssertStackTrace() { - // this variable can be set to true to suppress "assert failure" messages - static bool s_bNoAsserts = false; - - wxString msg; - msg.reserve(2048); - - // make life easier for people using VC++ IDE by using this format: like - // this, clicking on the message will take us immediately to the place of - // the failed assert - msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond); - - if ( szMsg ) - { - msg << _T(": ") << szMsg; - } - else // no message given - { - msg << _T('.'); - } + wxString stackTrace; -#if wxUSE_STACKWALKER +#if wxUSE_DBGHELP + // check that we can get the stack trace before trying to do it + if ( !wxDbgHelpDLL::Init() ) + return stackTrace; +#endif + class StackDump : public wxStackWalker { public: @@ -785,23 +756,53 @@ void ShowAssertDialog(const wxChar *szFile, StackDump dump; dump.Walk(5); // don't show OnAssert() call itself - wxString stackTrace = dump.GetStackTrace(); + stackTrace = dump.GetStackTrace(); // don't show more than maxLines or we could get a dialog too tall to be // shown on screen: 20 should be ok everywhere as even with 15 pixel high // characters it is still only 300 pixels... - const int maxLines = 20; - int count = stackTrace.Freq(wxT('\n')); - if (count > maxLines) + static const int maxLines = 20; + const int count = stackTrace.Freq(wxT('\n')); + for ( int i = 0; i < count - maxLines; i++ ) + stackTrace = stackTrace.BeforeLast(wxT('\n')); + + return stackTrace; +} +#endif // wxUSE_STACKWALKER + +// show the assert modal dialog +static +void ShowAssertDialog(const wxChar *szFile, + int nLine, + const wxChar *szCond, + const wxChar *szMsg, + wxAppTraits *traits) +{ + // this variable can be set to true to suppress "assert failure" messages + static bool s_bNoAsserts = false; + + wxString msg; + msg.reserve(2048); + + // make life easier for people using VC++ IDE by using this format: like + // this, clicking on the message will take us immediately to the place of + // the failed assert + msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond); + + if ( szMsg ) { - int i; - for (i = 0; i < count - maxLines; i++) - stackTrace = stackTrace.BeforeLast(wxT('\n')); + msg << _T(": ") << szMsg; } + else // no message given + { + msg << _T('.'); + } + +#if wxUSE_STACKWALKER + const wxString stackTrace = GetAssertStackTrace(); if ( !stackTrace.empty() ) { - msg << _T("\n\nCall stack:\n") - << stackTrace; + msg << _T("\n\nCall stack:\n") << stackTrace; } #endif // wxUSE_STACKWALKER