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;
}
// 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()
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();
}
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);
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
wxAssertHandler_t wxTheAssertHandler = wxDefaultAssertHandler;
+void wxSetDefaultAssertHandler()
+{
+ wxTheAssertHandler = wxDefaultAssertHandler;
+}
+
void wxOnAssert(const wxString& file,
int line,
const wxString& func,
//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;
}
// 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