X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a6384ca1e6e9a84f755dbca28875a5e89267766..6e1609b1e0784f299933742e02c58462df809acc:/src/common/init.cpp?ds=sidebyside diff --git a/src/common/init.cpp b/src/common/init.cpp index b01d39cd9b..ee24148576 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -29,12 +29,12 @@ #include "wx/log.h" #include "wx/thread.h" #include "wx/intl.h" + #include "wx/module.h" #endif #include "wx/init.h" #include "wx/ptr_scpd.h" -#include "wx/module.h" #include "wx/except.h" #if defined(__WXMSW__) && defined(__WXDEBUG__) @@ -176,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() @@ -211,6 +220,9 @@ 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 @@ -320,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(); @@ -382,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; } @@ -449,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