From 52051a08de77167c20ba73f499646e90b6466f63 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 26 Nov 2014 12:24:05 +0100 Subject: [PATCH] ActivityMonitor: catch the exception Having the app abort because of an uncaught exception when out of memory is not user friendly. Just stop drawing the graphs if that ever happens. --- src/apps/activitymonitor/ActivityView.cpp | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index cd3eea4ce5..6bbd9eb082 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -1405,20 +1405,27 @@ ActivityView::_DrawHistory(bool drawBackground) view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN); view->MovePenTo(B_ORIGIN); - view->BeginLineArray(steps - viewValues->Start() - 1); + try { + view->BeginLineArray(steps - viewValues->Start() - 1); - BPoint prev; + BPoint prev; - for (uint32 j = viewValues->Start(); j < steps; x += step, j++) { - float y = _PositionForValue(source, values, - viewValues->ValueAt(j)); + for (uint32 j = viewValues->Start(); j < steps; x += step, j++) { + float y = _PositionForValue(source, values, + viewValues->ValueAt(j)); - if (first) { - first = false; - } else - view->AddLine(prev, BPoint(x, y), source->Color()); + if (first) { + first = false; + } else + view->AddLine(prev, BPoint(x, y), source->Color()); - prev.Set(x, y); + prev.Set(x, y); + } + + } catch(std::bad_alloc) { + // Not enough memory to allocate the line array. + // TODO we could try to draw using the slower but less memory + // consuming solution using StrokeLine. } view->EndLineArray();