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
+27 -12
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,27 +83,30 @@ 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)
{ {
fOpStack.push(OP_LINETO | lineCount); fOpStack.push(OP_LINETO | lineCount);
for(int32 i = 0;i < lineCount;i++) for (int32 i = 0; i < lineCount; i++)
fPtStack.push(linePts[i]); fPtStack.push(linePts[i]);
return B_OK; return B_OK;
} }
status_t status_t
ShapePainter::IterateBezierTo(int32 bezierCount, BPoint *bezierPts) ShapePainter::IterateBezierTo(int32 bezierCount, BPoint *bezierPts)
{ {
bezierCount *= 3; bezierCount *= 3;
fOpStack.push(OP_BEZIERTO | bezierCount); fOpStack.push(OP_BEZIERTO | bezierCount);
for(int32 i = 0;i < bezierCount;i++) for (int32 i = 0; i < bezierCount; i++)
fPtStack.push(bezierPts[i]); fPtStack.push(bezierPts[i]);
return B_OK; return B_OK;
} }
status_t status_t
ShapePainter::IterateClose(void) ShapePainter::IterateClose(void)
{ {
@@ -108,27 +115,32 @@ 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; if (opCount > 0 && ptCount > 0) {
BPoint *ptList;
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;
for(i = (opCount - 1);i >= 0;i--) { BPoint *ptList = new (std::nothrow) BPoint[ptCount];
if (ptList == NULL) {
delete[] opList;
return;
}
for (i = (opCount - 1); i >= 0; i--) {
opList[i] = fOpStack.top(); opList[i] = fOpStack.top();
fOpStack.pop(); fOpStack.pop();
} }
for(i = (ptCount - 1);i >= 0;i--) { for (i = (ptCount - 1); i >= 0; i--) {
ptList[i] = fPtStack.top(); ptList[i] = fPtStack.top();
fPtStack.pop(); fPtStack.pop();
view->ConvertToScreenForDrawing(&ptList[i]); view->ConvertToScreenForDrawing(&ptList[i]);
@@ -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;
} }
} }