Handle out of memory conditions in the constructors more gracefully. We might end up using set_size() for every allocation (would probably make more sense)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
84063c1f44
commit
b0f02f2065
@ -49,15 +49,20 @@
|
|||||||
#include <RegionSupport.h>
|
#include <RegionSupport.h>
|
||||||
|
|
||||||
|
|
||||||
|
const static int32 kInitialDataSize = 8;
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Initializes a region. The region will have no rects,
|
/*! \brief Initializes a region. The region will have no rects,
|
||||||
and its bound will be invalid.
|
and its bound will be invalid.
|
||||||
*/
|
*/
|
||||||
BRegion::BRegion()
|
BRegion::BRegion()
|
||||||
:
|
:
|
||||||
data_size(8),
|
data_size(0),
|
||||||
data(NULL)
|
data(NULL)
|
||||||
{
|
{
|
||||||
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
|
data = (clipping_rect *)malloc(kInitialDataSize * sizeof(clipping_rect));
|
||||||
|
if (data != NULL)
|
||||||
|
data_size = kInitialDataSize;
|
||||||
|
|
||||||
Support::ZeroRegion(*this);
|
Support::ZeroRegion(*this);
|
||||||
}
|
}
|
||||||
@ -68,18 +73,19 @@ BRegion::BRegion()
|
|||||||
*/
|
*/
|
||||||
BRegion::BRegion(const BRegion ®ion)
|
BRegion::BRegion(const BRegion ®ion)
|
||||||
:
|
:
|
||||||
|
data_size(0),
|
||||||
data(NULL)
|
data(NULL)
|
||||||
{
|
{
|
||||||
bound = region.bound;
|
const int32 size = region.data_size > 0 ? region.data_size : 1;
|
||||||
count = region.count;
|
|
||||||
data_size = region.data_size;
|
|
||||||
|
|
||||||
if (data_size <= 0)
|
data = (clipping_rect *)malloc(size * sizeof(clipping_rect));
|
||||||
data_size = 1;
|
if (data != NULL) {
|
||||||
|
data_size = size;
|
||||||
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
|
bound = region.bound;
|
||||||
|
count = region.count;
|
||||||
memcpy(data, region.data, count * sizeof(clipping_rect));
|
memcpy(data, region.data, count * sizeof(clipping_rect));
|
||||||
|
} else
|
||||||
|
Support::ZeroRegion(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -88,12 +94,15 @@ BRegion::BRegion(const BRegion ®ion)
|
|||||||
*/
|
*/
|
||||||
BRegion::BRegion(const BRect rect)
|
BRegion::BRegion(const BRect rect)
|
||||||
:
|
:
|
||||||
data_size(8),
|
data_size(0),
|
||||||
data(NULL)
|
data(NULL)
|
||||||
{
|
{
|
||||||
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
|
data = (clipping_rect *)malloc(kInitialDataSize * sizeof(clipping_rect));
|
||||||
|
if (data != NULL) {
|
||||||
Set(rect);
|
data_size = kInitialDataSize;
|
||||||
|
Set(rect);
|
||||||
|
} else
|
||||||
|
Support::ZeroRegion(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user