[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 1140
Date       : Fri May 19 20:49:44 BST 2006

Changed paths:
   M /Trunk/XaraLX/wxOil/camelot.cpp
   M /Trunk/XaraLX/wxOil/errors.cpp
   M /Trunk/XaraLX/wxOil/errors.h
   M /Trunk/XaraLX/wxOil/stdwx.h
   M /Trunk/XaraLX/wxOil/xrc/EN/xaralxonly-strings.xrc

Nicer exception handling box
Debug report dialog


Diff:
Index: Trunk/XaraLX/wxOil/camelot.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camelot.cpp	(revision 1139)
+++ Trunk/XaraLX/wxOil/camelot.cpp	(revision 1140)
@@ -1696,8 +1696,7 @@
 	if (recursionguard)
 	{	
 		// Oh dear, an error occurred whilst we had our box up. Exit immediately
-		recursionguard++;
-		if (recursionguard > 1)
+		if (recursionguard++ > 1)
 		{
 			abort(); // do not even try to go through wx
 			_exit(1); // how did we get here?
@@ -1711,59 +1710,132 @@
 
 	recursionguard++;
 
-	// Ensure we are reinstated as the signal handler
-	::wxHandleFatalExceptions(FALSE);
-	::wxHandleFatalExceptions(TRUE);
+	// Put this bit in a block so strings etc. allocated are deallocated before we go generate our own stack frame
+	do
+	{
+		// Ensure we are reinstated as the signal handler
+		::wxHandleFatalExceptions(FALSE);
+		::wxHandleFatalExceptions(TRUE);
 
-	DisableSystem();
+// This bit of code is currently not operative - looking into wxDebugReport instead
+#ifdef EXCEPTION_LOCATION
+		String_256 location(_R(IDS_DOOMUNKNOWN));
+		// On platforms that support it, we try and find the appropriate error
+#if !defined(__WXMAC__) && !defined(__FreeBSD__)
+#define SWMAXLEVEL 200
+		class StackWalker : public wxStackWalker
+		{
+		public:
+			wxArrayString ArrayOfRefs;
+			wxArrayString ArrayOfDetails;
+			StackWalker() {ArrayOfRefs.SetCount(SWMAXLEVEL);ArrayOfDetails.SetCount(SWMAXLEVEL);}
+			virtual void OnStackFrame(const wxStackFrame & frame)
+			{
+				wxString details;
+				wxString fn=frame.GetFileName();
+				UINT32 line=frame.GetLine();
+				UINT32 level=frame.GetLevel();
+				details.Printf(_T("%d %s:%d %s"), level, fn.c_str(),
+							line, frame.GetName().c_str());
+#ifdef _DEBUG
+				wxLogDebug(details);
+#endif
+				if (level<SWMAXLEVEL)
+				{
+					ArrayOfDetails[level]=details;
+					details.Printf(_T("%s:%d"), fn.c_str(), line);
+					ArrayOfRefs[level]=details;
+				}
+			}
+		};
 
-	Progress::Smash(TRUE); // smash the progress bar
+		TRACE(_T("Debug trace"));
+		StackWalker s;
+		s.Walk();
+		// look 4 deep into the stack frame
+		if (s.ArrayOfRefs[5].Length() >= 3)
+			location=(const TCHAR *)(s.ArrayOfRefs[5]);
+#endif
+#endif
+
+		DisableSystem();
 	
-	// Relase the mouse if captured
-	wxWindow *pCapture=wxWindow::GetCapture();
-	if (pCapture)
-		pCapture->ReleaseMouse();
+		Progress::Smash(TRUE); // smash the progress bar
+		
+		// Relase the mouse if captured
+		wxWindow *pCapture=wxWindow::GetCapture();
+		if (pCapture)
+			pCapture->ReleaseMouse();
+	
+		if (Error::ErrorBoxRecurse)
+		{
+			INT32 result=wxYES;
 
-	INT32 result=wxYES;
-	// Start a new block here so that these variables get released at the end
-	if (InInitOrDeInit)
-	{
-	// We'll try and get the string for the message box from resources. If the resource system is dead,
-		// they won't be able to carry on working anyway.
-		String_256 PortentOfDoom(_R(IDS_DOOMMESSAGE2));
-		String_256 TitleOfDoom(_R(IDS_DOOMTITLE));
-		result = ::wxMessageBox(wxString((TCHAR *)PortentOfDoom), wxString((TCHAR *)TitleOfDoom), wxICON_ERROR); // this will be wxOK, not wxYES
-	}
-	else
-	{
-		// We'll try and get the string for the message box from resources. If the resource system is dead,
-		// they won't be able to carry on working anyway.
-		String_256 PortentOfDoom(_R(IDS_DOOMMESSAGE));
-		String_256 TitleOfDoom(_R(IDS_DOOMTITLE));
-		result = ::wxMessageBox(wxString((TCHAR *)PortentOfDoom), wxString((TCHAR *)TitleOfDoom), wxICON_ERROR | wxYES_NO);
-	}
+			// We're in an error box - don't ask the error system to put up the box, do it manually
+			if (InInitOrDeInit)
+			{
+			// We'll try and get the string for the message box from resources. If the resource system is dead,
+				// they won't be able to carry on working anyway.
+				String_256 PortentOfDoom(_R(IDS_DOOMMESSAGE2));
+				String_256 TitleOfDoom(_R(IDS_DOOMTITLE));
+				result = ::wxMessageBox(wxString((TCHAR *)PortentOfDoom), wxString((TCHAR *)TitleOfDoom), wxICON_ERROR); // this will be wxOK, not wxYES
+			}
+			else
+			{
+				// We'll try and get the string for the message box from resources. If the resource system is dead,
+				// they won't be able to carry on working anyway.
+				String_256 PortentOfDoom(_R(IDS_DOOMMESSAGE));
+				String_256 TitleOfDoom(_R(IDS_DOOMTITLE));
+				result = ::wxMessageBox(wxString((TCHAR *)PortentOfDoom), wxString((TCHAR *)TitleOfDoom), wxICON_ERROR | wxYES_NO);
+			}
+		
+			if (InInitOrDeInit || (result != wxYES))
+			{
+				recursionguard--;
+				return; // drop back into exception handler so as to quit.
+			}
+		}
+		else
+		{
+			// Use InformGeneral - this gives us the chance to produce a debug report
+			BOOL Quit=TRUE;
 
-	if (InInitOrDeInit || (result != wxYES))
-	{
-		recursionguard--;
-		return; // drop back into exception handler so as to quit.
-	}
+			if (InInitOrDeInit)
+				Quit = ::InformGeneral(ERRORTYPE_SERIOUS, 0, _R(IDS_DOOMMESSAGE2),
+										_R(IDS_DOOMQUITNOW), 0, 0, 0,
+										1, 1);
+			else
+				Quit = (::InformGeneral(ERRORTYPE_SERIOUS, 0, _R(IDS_DOOMMESSAGE),
+										_R(IDS_DOOMSAVEWORK), _R(IDS_DOOMQUITNOW), 0, 0,
+										1, 1) != 1);
 
-	if ( Error::IsInRenderThread() )
-	{
-		TRACE( _T("In RenderThread so clearing up system"));
-		Error::RenderThreadReset();
-		CamProfile::AtBase(CAMPROFILE_OTHER);
-	}
+			if (InInitOrDeInit || Quit)
+			{
+				recursionguard--;
+				return; // drop back into exception handler so as to quit.
+			}
+		}
 
-	GBrush::ResetOnFatalError(); // this clears an annoying ensure
+	
+		if ( Error::IsInRenderThread() )
+		{
+			TRACE( _T("In RenderThread so clearing up system"));
+			Error::RenderThreadReset();
+			CamProfile::AtBase(CAMPROFILE_OTHER);
+		}
+	
+		GBrush::ResetOnFatalError(); // this clears an annoying ensure
+	
+		if (IsDisabled()) // Error box routines can enable it
+			EnableSystem();
 
-	EnableSystem();
-	recursionguard--;
+		recursionguard--;
+	
+		// Zap out main loop pointer
+		m_mainLoop=NULL;
 
-	// Zap out main loop pointer
-	m_mainLoop=NULL;
-
+	} while(0);
+	
 	// We'd like to jump back into the main loop. We can't throw() as allegedly this doesn't work through
 	// gtk's stack frames (being C not C++) on some compilers sometimes. And destroying things might
 	// be bad. We don't do setjmp/longjmp as that would leave objects on the stack in a state where they
Index: Trunk/XaraLX/wxOil/errors.h
===================================================================
--- Trunk/XaraLX/wxOil/errors.h	(revision 1139)
+++ Trunk/XaraLX/wxOil/errors.h	(revision 1140)
@@ -603,6 +603,8 @@
 	};
 #endif
 
+	static UINT32 ErrorBoxRecurse;
+
 };
 
 /***********************************************************************************************
Index: Trunk/XaraLX/wxOil/errors.cpp
===================================================================
--- Trunk/XaraLX/wxOil/errors.cpp	(revision 1139)
+++ Trunk/XaraLX/wxOil/errors.cpp	(revision 1140)
@@ -135,7 +135,7 @@
 
 static BOOL ErrorHasBeenReported = TRUE;
 static UINT32	InSetError = 0;			// In either of the SetError routines
-static UINT32 ErrorBoxRecurse = 0;	// Incremented as per how many recursive error boxes we have
+UINT32 Error::ErrorBoxRecurse = 0;	// Incremented as per how many recursive error boxes we have
 
 // Used to indicate what kind of error message is currently defined.
 typedef enum
@@ -370,6 +370,16 @@
 			HelpUser(m_nHelpContext);
 #endif
 		}
+		else if (id == _R(IDS_ERRORBOX_DEBUGREPORT))
+		{
+			wxDebugReport report;
+			wxDebugReportPreviewStd preview;
+		
+			report.AddAll();
+		
+			if ( preview.Show(report) )
+				report.Process();
+		}
 		else
 		{
 			EndModal(id);
@@ -394,7 +404,7 @@
 	// Make sure there is at least one valid button.
 	if (Butt1 == 0) Butt1 = _R(IDS_OK);
 
-	if (ErrorBoxRecurse)
+	if (Error::ErrorBoxRecurse)
 	{
 		// Oh dear oh dear. Someone wants to put up an error box in the error handler. This is
 		// **BAD** news. The most likely cause is an exception within this routine (or the other
@@ -405,7 +415,7 @@
 		return(OK);
 	}
 
-	ErrorBoxRecurse++;
+	Error::ErrorBoxRecurse++;
 	if (ErrorMsg != 0)
 	{
 		// It's a new error message
@@ -422,6 +432,8 @@
 	// we should get our bitmap from the OS
 	ResourceID TitleID = 0;
 
+	ResourceID DebugReport = 0;
+
 	wxArtID bitmap=wxART_MISSING_IMAGE;
 
 	switch (Error)
@@ -448,12 +460,14 @@
 			//MessageBeep(MB_ICONHAND);
 			bitmap = wxART_ERROR;
 			TitleID = _R(IDS_ERRORBOX_SERIOUS);
+			DebugReport = _R(IDS_ERRORBOX_DEBUGREPORT);
 			break;
 
 		case ERRORTYPE_ENSURE:
 			//MessageBeep(MB_ICONHAND);
 			bitmap = wxART_ERROR;
 			TitleID = _R(IDS_ERRORBOX_ENSURE);
+			DebugReport = _R(IDS_ERRORBOX_DEBUGREPORT);
 			break;
 
 		case ERRORTYPE_ERROR:
@@ -474,7 +488,7 @@
 	if (!pBox)
 	{
 		Beep();
-		ErrorBoxRecurse--;
+		Error::ErrorBoxRecurse--;
 		return OK;
 	}
 
@@ -490,7 +504,7 @@
 	if (!pVSizer)
 	{
 		Beep();
-		ErrorBoxRecurse--;
+		Error::ErrorBoxRecurse--;
 		delete pBox;
 		return OK;
 	}
@@ -500,7 +514,7 @@
 	if (!pMessageSizer)
 	{
 		Beep();
-		ErrorBoxRecurse--;
+		Error::ErrorBoxRecurse--;
 		delete pBox;
 		return OK;
 	}
@@ -517,7 +531,7 @@
 		if (!pStaticBitmap)
 		{
 			Beep();
-			ErrorBoxRecurse--;
+			Error::ErrorBoxRecurse--;
 			delete pBox;
 			return OK;
 		}
@@ -538,7 +552,7 @@
 	if (!pMessage)
 	{
 		Beep();
-		ErrorBoxRecurse--;
+		Error::ErrorBoxRecurse--;
 		delete pBox;
 		return OK;
 	}
@@ -551,20 +565,22 @@
 	if (!pButtonSizer)
 	{
 		Beep();
-		ErrorBoxRecurse--;
+		Error::ErrorBoxRecurse--;
 		delete pBox;
 		return OK;
 	}
     pVSizer->Add(pButtonSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
-	wxButton * pButt[6]; // see help below, note we don't use zero, 5 is reserved for help
-	ResourceID butres[6];
+#define EB_MAXBUTS 7
+	wxButton * pButt[EB_MAXBUTS]; // see help below, note we don't use zero, 5 is reserved for help
+	ResourceID butres[EB_MAXBUTS];
 	butres[0]=0;
 	butres[1]=Butt1;
 	butres[2]=Butt2;
 	butres[3]=Butt3;
 	butres[4]=Butt4;
-	butres[5]=0;
+	butres[5]=0; // for IDS_HELP - see below
+	butres[6]=DebugReport;
 
 #if !defined(EXCLUDE_FROM_RALPH)
 	// See if there is any on-line help associated with the given warning/error message.
@@ -574,7 +590,7 @@
 #endif
 	
 	INT32 butt;
-	for (butt=0; butt<=5; butt++)
+	for (butt=0; butt<EB_MAXBUTS; butt++)
 	{
 		if (butres[butt])
 		{
@@ -583,17 +599,22 @@
 			if (!pButt[butt])
 			{
 				Beep();
-				ErrorBoxRecurse--;
+				Error::ErrorBoxRecurse--;
 				delete pBox;
 				return OK;
 			}
-			if (butres[butt] == (ResourceID)OK)
-				pButt[butt]->SetDefault();
 		}
 		else
 			pButt[butt]=NULL;
 	}
 
+	// Set the default
+	if ( ((UINT32)OK <EB_MAXBUTS) && butres[OK] && pButt[OK])
+	{
+		pButt[OK]->SetDefault();
+		pBox->SetDefaultItem(pButt[OK]);
+	}
+
     pBox->GetSizer()->Fit(pBox);
     pBox->GetSizer()->SetSizeHints(pBox);
     pBox->Centre();
@@ -621,7 +642,7 @@
 	ResourceID pressed = pBox->ShowModal();
 	INT32 result = Cancel;
 
-	for (butt=0; butt<=5; butt++)
+	for (butt=0; butt<EB_MAXBUTS; butt++)
 	{
 		if (butres[butt] == pressed)
 			result = butt;
@@ -658,7 +679,7 @@
 	ErrorHasBeenReported = TRUE;
 	Error::ClearError();
 		
-	ErrorBoxRecurse--;
+	Error::ErrorBoxRecurse--;
 
 	// if we were in a drag operation, cancel it (to prevent invalid drag state) fixes #11455
 	DragManagerOp::AbortDrag();
@@ -1725,11 +1746,11 @@
 void Error::DumpStack(UINT32 frames)
 {
 #ifdef _DEBUG
-#ifndef __WXMAC__
+#if !defined(__WXMAC__) && !defined(__FreeBSD__)
 	Error::StackWalker s;
 	s.Walk(frames);
 #else
-	TRACE( _T("Request to dump stack not supported on WXMAC") );
+	TRACE( _T("Request to dump stack not supported on this platform") );
 #endif
 #endif
 }
Index: Trunk/XaraLX/wxOil/xrc/EN/xaralxonly-strings.xrc
===================================================================
--- Trunk/XaraLX/wxOil/xrc/EN/xaralxonly-strings.xrc	(revision 1139)
+++ Trunk/XaraLX/wxOil/xrc/EN/xaralxonly-strings.xrc	(revision 1140)
@@ -311,6 +311,30 @@
 					<label>Xara LX</label>
 				</object>
 			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_DOOMUNKNOWN">
+					<label>Unknown</label>
+				</object>
+			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_DOOMQUITNOW">
+					<label>&Exit XaraLX now</label>
+				</object>
+			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_DOOMSAVEWORK">
+					<label>Attempt to &Save your work</label>
+				</object>
+			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_ERRORBOX_DEBUGREPORT">
+					<label>Send Error Log</label>
+				</object>
+			</object>
 		</object>
 	</object>
 </resource>
Index: Trunk/XaraLX/wxOil/stdwx.h
===================================================================
--- Trunk/XaraLX/wxOil/stdwx.h	(revision 1139)
+++ Trunk/XaraLX/wxOil/stdwx.h	(revision 1140)
@@ -106,6 +106,7 @@
 #include <wx/config.h>
 #include <wx/cshelp.h>
 #include <wx/dcbuffer.h>
+#include <wx/debugrpt.h>
 #include <wx/display.h>
 #include <wx/dir.h>
 #include <wx/docmdi.h>


Xara