We were leaking memory every time a BPicture was drawn. Also check if the allocations succeeded. Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27197 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2008-08-25 13:57:29 +00:00
parent e1d9b81384
commit d02fd30b90
+22 -7
View File
@@ -54,15 +54,18 @@ class ShapePainter : public BShapeIterator {
stack<BPoint> fPtStack; stack<BPoint> fPtStack;
}; };
ShapePainter::ShapePainter() ShapePainter::ShapePainter()
: BShapeIterator() : BShapeIterator()
{ {
} }
ShapePainter::~ShapePainter() ShapePainter::~ShapePainter()
{ {
} }
status_t status_t
ShapePainter::Iterate(const BShape *shape) ShapePainter::Iterate(const BShape *shape)
{ {
@@ -70,6 +73,7 @@ ShapePainter::Iterate(const BShape *shape)
return BShapeIterator::Iterate(const_cast<BShape *>(shape)); return BShapeIterator::Iterate(const_cast<BShape *>(shape));
} }
status_t status_t
ShapePainter::IterateMoveTo(BPoint *point) ShapePainter::IterateMoveTo(BPoint *point)
{ {
@@ -79,6 +83,7 @@ ShapePainter::IterateMoveTo(BPoint *point)
return B_OK; return B_OK;
} }
status_t status_t
ShapePainter::IterateLineTo(int32 lineCount, BPoint *linePts) ShapePainter::IterateLineTo(int32 lineCount, BPoint *linePts)
{ {
@@ -89,6 +94,7 @@ ShapePainter::IterateLineTo(int32 lineCount, BPoint *linePts)
return B_OK; return B_OK;
} }
status_t status_t
ShapePainter::IterateBezierTo(int32 bezierCount, BPoint *bezierPts) ShapePainter::IterateBezierTo(int32 bezierCount, BPoint *bezierPts)
{ {
@@ -100,6 +106,7 @@ ShapePainter::IterateBezierTo(int32 bezierCount, BPoint *bezierPts)
return B_OK; return B_OK;
} }
status_t status_t
ShapePainter::IterateClose(void) ShapePainter::IterateClose(void)
{ {
@@ -108,20 +115,25 @@ ShapePainter::IterateClose(void)
return B_OK; return B_OK;
} }
void void
ShapePainter::Draw(View *view, BRect frame, bool filled) ShapePainter::Draw(View *view, BRect frame, bool filled)
{ {
// We're going to draw the currently iterated shape. // We're going to draw the currently iterated shape.
int32 opCount, ptCount; int32 opCount = fOpStack.size();
opCount = fOpStack.size(); int32 ptCount = fPtStack.size();
ptCount = fPtStack.size();
uint32 *opList;
BPoint *ptList;
if (opCount > 0 && ptCount > 0) { if (opCount > 0 && ptCount > 0) {
int32 i; int32 i;
opList = new uint32[opCount]; uint32 *opList = new (std::nothrow) uint32[opCount];
ptList = new BPoint[ptCount]; if (opList == NULL)
return;
BPoint *ptList = new (std::nothrow) BPoint[ptCount];
if (ptList == NULL) {
delete[] opList;
return;
}
for (i = (opCount - 1); i >= 0; i--) { for (i = (opCount - 1); i >= 0; i--) {
opList[i] = fOpStack.top(); opList[i] = fOpStack.top();
@@ -136,6 +148,9 @@ ShapePainter::Draw(View *view, BRect frame, bool filled)
view->Window()->GetDrawingEngine()->DrawShape(frame, opCount, opList, ptCount, ptList, view->Window()->GetDrawingEngine()->DrawShape(frame, opCount, opList, ptCount, ptList,
filled); filled);
delete[] opList;
delete[] ptList;
} }
} }