wxLogXXX() functions called near app termiantion shouldn't crash

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1765 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-02-23 22:49:26 +00:00
parent 90022ddc1e
commit e5c0b16a78

View File

@ -9,6 +9,14 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// declarations
// ===========================================================================
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "app.h" #pragma implementation "app.h"
#endif #endif
@ -56,11 +64,14 @@
#include "wx/resource.h" #include "wx/resource.h"
#endif #endif
// To UG: there's no point in putting this #if here // OLE is used for drag-and-drop, clipboard, OLE Automation...
// if you don't do the same for the Ole calls further down. #if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
// Also, OLE is used not just for drag and drop (it's used by automatn.cpp). #undef wxUSE_OLE
// #if wxUSE_DRAG_AND_DROP
#if !defined(__GNUWIN32__) && !defined(__SC__) && !defined(__SALFORDC__) #define wxUSE_OLE 0
#endif // broken compilers
#if wxUSE_OLE
#include <ole2.h> #include <ole2.h>
#endif #endif
@ -73,6 +84,10 @@
#include "wx/msw/msvcrt.h" #include "wx/msw/msvcrt.h"
// ---------------------------------------------------------------------------
// global variables
// ---------------------------------------------------------------------------
extern char *wxBuffer; extern char *wxBuffer;
extern char *wxOsVersion; extern char *wxOsVersion;
extern wxList *wxWinHandleList; extern wxList *wxWinHandleList;
@ -84,7 +99,7 @@ HINSTANCE wxhInstance = 0;
static MSG s_currentMsg; static MSG s_currentMsg;
wxApp *wxTheApp = NULL; wxApp *wxTheApp = NULL;
// @@ why not const? and not static? // FIXME why not const? and not static?
char wxFrameClassName[] = "wxFrameClass"; char wxFrameClassName[] = "wxFrameClass";
char wxMDIFrameClassName[] = "wxMDIFrameClass"; char wxMDIFrameClassName[] = "wxMDIFrameClass";
char wxMDIChildFrameClassName[] = "wxMDIChildFrameClass"; char wxMDIChildFrameClassName[] = "wxMDIChildFrameClass";
@ -103,6 +118,24 @@ HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
LRESULT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); LRESULT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
#if defined(__WIN95__) && !defined(__TWIN32__)
#define wxUSE_RICHEDIT 1
#else
#define wxUSE_RICHEDIT 0
#endif
#if wxUSE_RICHEDIT
static HINSTANCE gs_hRichEdit = (HINSTANCE) NULL;
#endif
// ===========================================================================
// implementation
// ===========================================================================
// ---------------------------------------------------------------------------
// wxApp
// ---------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
@ -115,18 +148,7 @@ LRESULT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
long wxApp::sm_lastMessageTime = 0; long wxApp::sm_lastMessageTime = 0;
#if defined(__WIN95__) && !defined(__TWIN32__)
#define wxUSE_RICHEDIT 1
#else
#define wxUSE_RICHEDIT 0
#endif
#if wxUSE_RICHEDIT
static HINSTANCE gs_hRichEdit = (HINSTANCE) NULL;
#endif
//// Initialize //// Initialize
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
// Some people may wish to use this, but // Some people may wish to use this, but
@ -135,7 +157,7 @@ bool wxApp::Initialize()
// wxRedirectIOToConsole(); // wxRedirectIOToConsole();
#endif #endif
wxBuffer = new char[1500]; wxBuffer = new char[1500]; // FIXME
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
@ -163,15 +185,14 @@ bool wxApp::Initialize()
if (gs_hRichEdit == (HINSTANCE) NULL) if (gs_hRichEdit == (HINSTANCE) NULL)
{ {
wxMessageBox("Could not initialise Rich Edit DLL"); wxLogError(_("Could not initialise Rich Edit DLL"));
} }
#endif #endif // wxUSE_RICHEDIT
#endif #endif // __WIN95__
int iMsg = 96;
// for OLE, enlarge message queue to be as large as possible // for OLE, enlarge message queue to be as large as possible
int iMsg = 96;
while (!SetMessageQueue(iMsg) && (iMsg -= 8)); while (!SetMessageQueue(iMsg) && (iMsg -= 8));
/* /*
@ -186,15 +207,15 @@ bool wxApp::Initialize()
} }
*/ */
#if !defined(__GNUWIN32__) && !defined(__SC__) && !defined(__SALFORDC__) #if wxUSE_OLE
// we need to initialize OLE library // we need to initialize OLE library
if ( FAILED(::OleInitialize(NULL)) ) if ( FAILED(::OleInitialize(NULL)) )
wxFatalError(_("Cannot initialize OLE")); wxLogError(_("Cannot initialize OLE"));
#endif #endif
#if wxUSE_CTL3D #if wxUSE_CTL3D
if (!Ctl3dRegister(wxhInstance)) if (!Ctl3dRegister(wxhInstance))
wxFatalError("Cannot register CTL3D"); wxLogError("Cannot register CTL3D");
Ctl3dAutoSubclass(wxhInstance); Ctl3dAutoSubclass(wxhInstance);
#endif #endif
@ -445,10 +466,14 @@ void wxApp::CleanUp()
{ {
//// COMMON CLEANUP //// COMMON CLEANUP
// flush the logged messages if any // flush the logged messages if any and install a 'safer' log target: the
wxLog *pLog = wxLog::GetActiveTarget(); // default one (wxLogGui) can't be used after the resources are freed just
if ( pLog != NULL && pLog->HasPendingMessages() ) // below and the user suppliedo ne might be even more unsafe (using any
pLog->Flush(); // wxWindows GUI function is unsafe starting from now)
wxLog::DontCreateOnDemand();
// this will flush the old messages if any
delete wxLog::SetActiveTarget(new wxLogStderr);
// One last chance for pending objects to be cleaned up // One last chance for pending objects to be cleaned up
wxTheApp->DeletePendingObjects(); wxTheApp->DeletePendingObjects();
@ -461,10 +486,9 @@ void wxApp::CleanUp()
// wxDefaultResourceTable->ClearTable(); // wxDefaultResourceTable->ClearTable();
#endif #endif
// Indicate that the cursor can be freed, // Indicate that the cursor can be freed, so that cursor won't be deleted
// so that cursor won't be deleted by deleting // by deleting the bitmap list before g_globalCursor goes out of scope
// the bitmap list before g_globalCursor goes out // (double deletion of the cursor).
// of scope (double deletion of the cursor).
wxSetCursor(wxNullCursor); wxSetCursor(wxNullCursor);
delete g_globalCursor; delete g_globalCursor;
@ -515,7 +539,7 @@ void wxApp::CleanUp()
if ( wxDisableButtonBrush ) if ( wxDisableButtonBrush )
::DeleteObject( wxDisableButtonBrush ) ; ::DeleteObject( wxDisableButtonBrush ) ;
#if !defined(__GNUWIN32__) && !defined(__SC__) && !defined(__SALFORDC__) #if wxUSE_OLE
::OleUninitialize(); ::OleUninitialize();
#endif #endif
@ -546,13 +570,13 @@ void wxApp::CleanUp()
#endif #endif
// do it as the very last thing because everything else can log messages // do it as the very last thing because everything else can log messages
wxLog::DontCreateOnDemand();
delete wxLog::SetActiveTarget(NULL); delete wxLog::SetActiveTarget(NULL);
} }
#if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL)) #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
// temporarily disable this warning // temporarily disable this warning which would be generated in release builds
// because of __try
#ifdef __VISUALC__ #ifdef __VISUALC__
#pragma warning(disable: 4715) // not all control paths return a value #pragma warning(disable: 4715) // not all control paths return a value
#endif // Visual C++ #endif // Visual C++
@ -653,6 +677,13 @@ int wxEntry(WXHINSTANCE hInstance,
wxTheApp->OnFatalException(); wxTheApp->OnFatalException();
*/ */
// using wxLog would be unsafe here
::MessageBox(NULL,
_("Unrecoverable program error detected: "
" the application will terminate."),
_("Fatal Error"),
MB_APPLMODAL | MB_ICONSTOP | MB_OK);
::ExitProcess(3); // the same exit code as abort() ::ExitProcess(3); // the same exit code as abort()
// NOTREACHED // NOTREACHED
@ -677,22 +708,15 @@ int wxEntry(WXHINSTANCE hInstance)
// The app may have declared a global application object, but we recommend // The app may have declared a global application object, but we recommend
// the IMPLEMENT_APP macro is used instead, which sets an initializer function // the IMPLEMENT_APP macro is used instead, which sets an initializer function
// for delayed, dynamic app object construction. // for delayed, dynamic app object construction.
if (!wxTheApp) if (!wxTheApp)
{ {
if (!wxApp::GetInitializerFunction()) wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
{ "No initializer - use IMPLEMENT_APP macro." );
MessageBox(NULL, "No initializer - use IMPLEMENT_APP macro.", "wxWindows Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
return 0;
}
wxTheApp = (* wxApp::GetInitializerFunction()) (); wxTheApp = (* wxApp::GetInitializerFunction()) ();
} }
if (!wxTheApp) { wxCHECK_MSG( wxTheApp, 0, "You have to define an instance of wxApp!" );
MessageBox(NULL, "You have to define an instance of wxApp!", "wxWindows Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
return 0;
}
wxTheApp->argc = 0; wxTheApp->argc = 0;
wxTheApp->argv = NULL; wxTheApp->argv = NULL;
@ -701,8 +725,10 @@ int wxEntry(WXHINSTANCE hInstance)
wxTheApp->OnInit(); wxTheApp->OnInit();
if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->GetHWND()) { wxWindow *topWindow = wxTheApp->GetTopWindow();
wxTheApp->GetTopWindow()->Show(TRUE); if ( topWindow && topWindow->GetHWND())
{
topWindow->Show(TRUE);
} }
return 1; return 1;
@ -1102,8 +1128,9 @@ int wxApp::GetComCtl32Version() const
void wxExit() void wxExit()
{ {
wxLogError(_("Fatal error: exiting"));
wxApp::CleanUp(); wxApp::CleanUp();
FatalAppExit(0, "Fatal error: exiting");
} }
// Yield to incoming messages // Yield to incoming messages