Commit b7457a59 authored by twanvl's avatar twanvl

Catch all exceptions in onPaint functions, because otherwise we show a message...

Catch all exceptions in onPaint functions, because otherwise we show a message box. Message boxes while in a paint handler lead to a crash on win32.
Made a CATCH_ALL_ERRORS macro containing the common catch statements.
parent 78d5637c
...@@ -87,7 +87,9 @@ void CardViewer::onPaint(wxPaintEvent&) { ...@@ -87,7 +87,9 @@ void CardViewer::onPaint(wxPaintEvent&) {
// draw // draw
if (!up_to_date) { if (!up_to_date) {
up_to_date = true; up_to_date = true;
try {
draw(dc); draw(dc);
} CATCH_ALL_ERRORS(false); // don't show message boxes in onPaint!
} }
} }
......
...@@ -183,7 +183,9 @@ wxSize GalleryList::DoGetBestSize() const { ...@@ -183,7 +183,9 @@ wxSize GalleryList::DoGetBestSize() const {
void GalleryList::onPaint(wxPaintEvent&) { void GalleryList::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
try {
OnDraw(dc); OnDraw(dc);
} CATCH_ALL_ERRORS(false); // don't show message boxes in onPaint!
} }
void GalleryList::OnDraw(DC& dc) { void GalleryList::OnDraw(DC& dc) {
wxSize cs = GetClientSize(); wxSize cs = GetClientSize();
......
...@@ -985,6 +985,7 @@ size_t GraphControl::getDimensionality() const { ...@@ -985,6 +985,7 @@ size_t GraphControl::getDimensionality() const {
void GraphControl::onPaint(wxPaintEvent&) { void GraphControl::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
try {
wxSize cs = GetClientSize(); wxSize cs = GetClientSize();
RotatedDC rdc(dc, 0, RealRect(RealPoint(0,0),cs), 1, QUALITY_LOW); RotatedDC rdc(dc, 0, RealRect(RealPoint(0,0),cs), 1, QUALITY_LOW);
rdc.SetPen(*wxTRANSPARENT_PEN); rdc.SetPen(*wxTRANSPARENT_PEN);
...@@ -995,6 +996,7 @@ void GraphControl::onPaint(wxPaintEvent&) { ...@@ -995,6 +996,7 @@ void GraphControl::onPaint(wxPaintEvent&) {
graph->draw(rdc, current_item, (DrawLayer)layer); graph->draw(rdc, current_item, (DrawLayer)layer);
} }
} }
} CATCH_ALL_ERRORS(false); // don't show message boxes in onPaint!
} }
void GraphControl::onSize(wxSizeEvent&) { void GraphControl::onSize(wxSizeEvent&) {
......
...@@ -115,6 +115,7 @@ class PackageInfoPanel : public wxPanel { ...@@ -115,6 +115,7 @@ class PackageInfoPanel : public wxPanel {
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
void onPaint(wxPaintEvent&); void onPaint(wxPaintEvent&);
void draw(DC&);
}; };
PackageInfoPanel::PackageInfoPanel(Window* parent) PackageInfoPanel::PackageInfoPanel(Window* parent)
...@@ -128,6 +129,11 @@ void PackageInfoPanel::setPackage(const InstallablePackageP& package) { ...@@ -128,6 +129,11 @@ void PackageInfoPanel::setPackage(const InstallablePackageP& package) {
void PackageInfoPanel::onPaint(wxPaintEvent&) { void PackageInfoPanel::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
try {
draw(dc);
} CATCH_ALL_ERRORS(false); // don't show message boxes in onPaint!
}
void PackageInfoPanel::draw(DC& dc) {
wxSize cs = GetClientSize(); wxSize cs = GetClientSize();
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
......
...@@ -200,7 +200,9 @@ void SymbolControl::draw(DC& dc) { ...@@ -200,7 +200,9 @@ void SymbolControl::draw(DC& dc) {
} }
void SymbolControl::onPaint(wxPaintEvent&) { void SymbolControl::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
try {
draw(dc); draw(dc);
} CATCH_ALL_ERRORS(false); // don't show message boxes in onPaint!
} }
// ----------------------------------------------------------------------------- : Events // ----------------------------------------------------------------------------- : Events
......
...@@ -209,14 +209,7 @@ int MSE::OnRun() { ...@@ -209,14 +209,7 @@ int MSE::OnRun() {
(new WelcomeWindow())->Show(); (new WelcomeWindow())->Show();
return wxApp::OnRun(); return wxApp::OnRun();
} catch (const Error& e) { } CATCH_ALL_ERRORS(true);
handle_error(e, false);
} catch (const std::exception& e) {
// we don't throw std::exception ourselfs, so this is probably something serious
handle_error(InternalError(String(e.what(), IF_UNICODE(wxConvLocal, wxSTRING_MAXLEN) )), false);
} catch (...) {
handle_error(InternalError(_("An unexpected exception occurred!")), false);
}
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -234,13 +227,6 @@ int MSE::OnExit() { ...@@ -234,13 +227,6 @@ int MSE::OnExit() {
bool MSE::OnExceptionInMainLoop() { bool MSE::OnExceptionInMainLoop() {
try { try {
throw; // rethrow the exception, so we can examine it throw; // rethrow the exception, so we can examine it
} catch (const Error& e) { } CATCH_ALL_ERRORS(true);
handle_error(e, false);
} catch (const std::exception& e) {
// we don't throw std::exception ourselfs, so this is probably something serious
handle_error(InternalError(String(e.what(), IF_UNICODE(wxConvLocal, wxSTRING_MAXLEN) )), false);
} catch (...) {
handle_error(InternalError(_("An unexpected exception occurred!")), false);
}
return true; return true;
} }
...@@ -123,5 +123,17 @@ void handle_warning(const String& w, bool now = true); ...@@ -123,5 +123,17 @@ void handle_warning(const String& w, bool now = true);
/** Should be called repeatedly (e.g. in an onIdle event handler) */ /** Should be called repeatedly (e.g. in an onIdle event handler) */
void handle_pending_errors(); void handle_pending_errors();
/// Catch all types of errors, and pass then to handle_error
#define CATCH_ALL_ERRORS(handle_now) \
catch (const Error& e) { \
handle_error(e, false, handle_now); \
} catch (const std::exception& e) { \
/* we don't throw std::exception ourselfs, so this is probably something serious */ \
String message(e.what(), IF_UNICODE(wxConvLocal, wxSTRING_MAXLEN) ); \
handle_error(InternalError(message), false, handle_now); \
} catch (...) { \
handle_error(InternalError(_("An unexpected exception occurred!")), false, handle_now); \
}
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment