From 2c604c0df5eabe4a71c1a6ef0654924f9f5e1ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 5 Jun 2009 08:20:43 +0000 Subject: [PATCH] * CircularBuffer is now save to use even if the buffer allocation failed. This fixes bug #3985. * This happened as ViewHistory::Update() can obviously be called before the view is really layouted. Therefore it now restricts the view size to 16384. * Since the Update() happens in Draw(), it looks like this is actually a problem of our layout engine (as the size is computed via BView::Frame()). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30967 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/activitymonitor/ActivityView.cpp | 5 +++++ src/apps/activitymonitor/CircularBuffer.h | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index 73947ce6d1..689f79053f 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -225,6 +225,11 @@ void ViewHistory::Update(DataHistory* history, int32 width, int32 resolution, bigtime_t toTime, bigtime_t step, bigtime_t refresh) { + if (width > 16384) { + // ignore this - it seems the view hasn't been layouted yet + return; + } + // Check if we need to invalidate the existing values if ((int32)fValues.Size() != width || fResolution != resolution diff --git a/src/apps/activitymonitor/CircularBuffer.h b/src/apps/activitymonitor/CircularBuffer.h index 5063f7d349..12ff3ada55 100644 --- a/src/apps/activitymonitor/CircularBuffer.h +++ b/src/apps/activitymonitor/CircularBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef CIRCULAR_BUFFER_H @@ -40,7 +40,12 @@ public: fSize = size; fBuffer = (Type*)malloc(fSize * sizeof(Type)); - return fBuffer != NULL ? B_OK : B_NO_MEMORY; + if (fBuffer == NULL) { + fSize = 0; + return B_NO_MEMORY; + } + + return B_OK; } void MakeEmpty() @@ -61,7 +66,7 @@ public: Type* ItemAt(int32 index) const { - if (index >= (int32)fIn || index < 0) + if (index >= (int32)fIn || index < 0 || fBuffer == NULL) return NULL; return &fBuffer[(fFirst + index) % fSize]; @@ -75,7 +80,8 @@ public: else index = fFirst++; - fBuffer[index % fSize] = item; + if (fBuffer != NULL) + fBuffer[index % fSize] = item; } size_t Size() const