X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..4ee4c7b948e76377a6947d3ffbe5099870d0c3e9:/src/common/appbase.cpp diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 4851b5ac80..6523195492 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -154,6 +154,10 @@ wxAppConsoleBase::wxAppConsoleBase() wxAppConsoleBase::~wxAppConsoleBase() { + // we're being destroyed and using this object from now on may not work or + // even crash so don't leave dangling pointers to it + ms_appInstance = NULL; + delete m_traits; } @@ -161,21 +165,45 @@ wxAppConsoleBase::~wxAppConsoleBase() // initialization/cleanup // ---------------------------------------------------------------------------- -bool wxAppConsoleBase::Initialize(int& WXUNUSED(argc), wxChar **argv) +bool wxAppConsoleBase::Initialize(int& WXUNUSED(argc), wxChar **WXUNUSED(argv)) { #if wxUSE_INTL GetTraits()->SetLocale(); #endif // wxUSE_INTL + return true; +} + +wxString wxAppConsoleBase::GetAppName() const +{ + wxString name = m_appName; #ifndef __WXPALMOS__ - if ( m_appName.empty() && argv && argv[0] ) + if ( name.empty() ) { - // the application name is, by default, the name of its executable file - wxFileName::SplitPath(argv[0], NULL, &m_appName, NULL); + if ( argv ) + { + // the application name is, by default, the name of its executable file + wxFileName::SplitPath(argv[0], NULL, &name, NULL); + } } #endif // !__WXPALMOS__ + return name; +} - return true; +wxString wxAppConsoleBase::GetAppDisplayName() const +{ + // use the explicitly provided display name, if any + if ( !m_appDisplayName.empty() ) + return m_appDisplayName; + + // if the application name was explicitly set, use it as is as capitalizing + // it won't always produce good results + if ( !m_appName.empty() ) + return m_appName; + + // if neither is set, use the capitalized version of the program file as + // it's the most reasonable default + return GetAppName().Capitalize(); } wxEventLoopBase *wxAppConsoleBase::CreateMainLoop() @@ -340,6 +368,12 @@ bool wxAppConsoleBase::ProcessIdle() event.SetEventObject(this); ProcessEvent(event); +#if wxUSE_LOG + // flush the logged messages if any (do this after processing the events + // which could have logged new messages) + wxLog::FlushActive(); +#endif + return event.MoreRequested(); } @@ -838,22 +872,19 @@ void WXDLLIMPEXP_BASE wxMutexGuiLeave() bool wxAppTraitsBase::ShowAssertDialog(const wxString& msgOriginal) { #if wxDEBUG_LEVEL - wxString msg = msgOriginal; + wxString msg; #if wxUSE_STACKWALKER -#if !defined(__WXMSW__) - // on Unix stack frame generation may take some time, depending on the - // size of the executable mainly... warn the user that we are working - wxFprintf(stderr, wxT("[Debug] Generating a stack trace... please wait")); - fflush(stderr); -#endif - const wxString stackTrace = GetAssertStackTrace(); if ( !stackTrace.empty() ) + { msg << wxT("\n\nCall stack:\n") << stackTrace; + + wxMessageOutputDebug().Output(msg); + } #endif // wxUSE_STACKWALKER - return DoShowAssertDialog(msg); + return DoShowAssertDialog(msgOriginal + msg); #else // !wxDEBUG_LEVEL wxUnusedVar(msgOriginal); @@ -865,6 +896,15 @@ bool wxAppTraitsBase::ShowAssertDialog(const wxString& msgOriginal) wxString wxAppTraitsBase::GetAssertStackTrace() { #if wxDEBUG_LEVEL + +#if !defined(__WXMSW__) + // on Unix stack frame generation may take some time, depending on the + // size of the executable mainly... warn the user that we are working + wxFprintf(stderr, "Collecting stack trace information, please wait..."); + fflush(stderr); +#endif // !__WXMSW__ + + wxString stackTrace; class StackDump : public wxStackWalker @@ -1016,6 +1056,11 @@ wxDefaultAssertHandler(const wxString& file, wxAssertHandler_t wxTheAssertHandler = wxDefaultAssertHandler; +void wxSetDefaultAssertHandler() +{ + wxTheAssertHandler = wxDefaultAssertHandler; +} + void wxOnAssert(const wxString& file, int line, const wxString& func, @@ -1147,14 +1192,10 @@ bool DoShowAssertDialog(const wxString& msg) //case IDNO: nothing to do } #else // !__WXMSW__ - wxFprintf(stderr, wxT("%s\n"), msg.c_str()); - fflush(stderr); - - // TODO: ask the user to enter "Y" or "N" on the console? - wxTrap(); + wxUnusedVar(msg); #endif // __WXMSW__/!__WXMSW__ - // continue with the asserts + // continue with the asserts by default return false; } @@ -1197,27 +1238,15 @@ void ShowAssertDialog(const wxString& file, // since dialogs cannot be displayed if ( !wxThread::IsMain() ) { - msg += wxT(" [in child thread]"); - -#if defined(__WXMSW__) && !defined(__WXMICROWIN__) - msg << wxT("\r\n"); - OutputDebugString(msg.wx_str()); -#else - // send to stderr - wxFprintf(stderr, wxT("%s\n"), msg.c_str()); - fflush(stderr); -#endif - // He-e-e-e-elp!! we're asserting in a child thread - wxTrap(); + msg += wxString::Format(" [in thread %lx]", wxThread::GetCurrentId()); } - else #endif // wxUSE_THREADS + // log the assert in any case + wxMessageOutputDebug().Output(msg); + if ( !s_bNoAsserts ) { - // send it to the normal log destination - wxLogDebug(wxT("%s"), msg.c_str()); - if ( traits ) { // delegate showing assert dialog (if possible) to that class