X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/faa112c4ca49e1f1d9467107d6e54cb9986bd900..747d7d7c159a57015d7aa9d844f834b78f613272:/src/common/init.cpp diff --git a/src/common/init.cpp b/src/common/init.cpp index d126e10b8d..326ef09333 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: common/init.cpp +// Name: src/common/init.cpp // Purpose: initialisation for the library // Author: Vadim Zeitlin // Modified by: @@ -20,22 +20,21 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif //__BORLANDC__ #ifndef WX_PRECOMP #include "wx/app.h" - #include "wx/debug.h" #include "wx/filefn.h" #include "wx/log.h" - #include "wx/thread.h" #include "wx/intl.h" + #include "wx/module.h" #endif #include "wx/init.h" +#include "wx/thread.h" #include "wx/ptr_scpd.h" -#include "wx/module.h" #include "wx/except.h" #if defined(__WXMSW__) && defined(__WXDEBUG__) @@ -177,14 +176,23 @@ static struct InitData static void ConvertArgsToUnicode(int argc, char **argv) { gs_initData.argv = new wchar_t *[argc + 1]; + int wargc = 0; for ( int i = 0; i < argc; i++ ) { wxWCharBuffer buf(wxConvLocal.cMB2WX(argv[i])); - gs_initData.argv[i] = buf ? wxStrdup(buf) : NULL; + if ( !buf ) + { + wxLogWarning(_("Command line argument %d couldn't be converted to Unicode and will be ignored."), + i); + } + else // converted ok + { + gs_initData.argv[wargc++] = wxStrdup(buf); + } } - gs_initData.argc = argc; - gs_initData.argv[argc] = NULL; + gs_initData.argc = wargc; + gs_initData.argv[wargc] = NULL; } static void FreeConvertedArgs() @@ -212,12 +220,15 @@ static void FreeConvertedArgs() static bool DoCommonPreInit() { #if wxUSE_LOG + // Reset logging in case we were cleaned up and are being reinitialized. + wxLog::DoCreateOnDemand(); + // 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); + delete wxLog::SetActiveTarget(new wxLogBuffer); #endif // wxUSE_LOG return true; @@ -321,7 +332,7 @@ bool wxEntryStart(int& argc, char **argv) { ConvertArgsToUnicode(argc, argv); - if ( !wxEntryStart(argc, gs_initData.argv) ) + if ( !wxEntryStart(gs_initData.argc, gs_initData.argv) ) { FreeConvertedArgs(); @@ -383,8 +394,12 @@ void wxEntryCleanup() { wxTheApp->CleanUp(); - delete wxTheApp; + // reset the global pointer to it to NULL before destroying it as in + // some circumstances this can result in executing the code using + // wxTheApp and using half-destroyed object is no good + wxAppConsole * const app = wxApp::GetInstance(); wxApp::SetInstance(NULL); + delete app; } @@ -450,7 +465,7 @@ int wxEntry(int& argc, char **argv) { ConvertArgsToUnicode(argc, argv); - return wxEntry(argc, gs_initData.argv); + return wxEntry(gs_initData.argc, gs_initData.argv); } #endif // wxUSE_UNICODE @@ -481,4 +496,3 @@ void wxUninitialize() wxEntryCleanup(); } } -