From 1c7b2f01995f2c76e92408db8e80d049cc0ce467 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 6 Jun 2005 23:36:53 +0000 Subject: [PATCH] use wxLogBuffer to ensure that we don't lose error messages during initialization; only switch to wxLogGui when it's really safe to use it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34557 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/appbase.cpp | 8 -------- src/common/init.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index b333b2fc6c..0892aab62d 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -142,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; diff --git a/src/common/init.cpp b/src/common/init.cpp index a225bf6833..f15805e91f 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -209,6 +209,15 @@ static void FreeConvertedArgs() // initialization which is always done (not customizable) before wxApp creation static bool DoCommonPreInit() { +#if wxUSE_LOG + // install temporary log sink: we can't use wxLogGui before wxApp is + // constructed and if we use wxLogStderr, all messages during + // initialization simply disappear under Windows + // + // note that we will delete this log target below + wxLog::SetActiveTarget(new wxLogBuffer); +#endif // wxUSE_LOG + return true; } @@ -217,7 +226,13 @@ static bool DoCommonPostInit() { wxModule::RegisterModules(); - return wxModule::InitializeModules(); + if ( !wxModule::InitializeModules() ) + { + wxLogError(_("Initialization failed in post init, aborting.")); + return false; + } + + return true; } bool wxEntryStart(int& argc, wxChar **argv) @@ -286,6 +301,14 @@ bool wxEntryStart(int& argc, wxChar **argv) // and the cleanup object from doing cleanup callAppCleanup.Dismiss(); +#if wxUSE_LOG + // now that we have a valid wxApp (wxLogGui would have crashed if we used + // it before now), we can delete the temporary sink we had created for the + // initialization messages -- the next time logging function is called, the + // sink will be recreated but this time wxAppTraits will be used + delete wxLog::SetActiveTarget(NULL); +#endif // wxUSE_LOG + return true; } @@ -385,6 +408,8 @@ int wxEntryReal(int& argc, wxChar **argv) // library initialization if ( !wxEntryStart(argc, argv) ) { + // flush any log messages explaining why we failed + delete wxLog::SetActiveTarget(NULL); return -1; } -- 2.45.2