app_server: some missing std::nothrow and error checks.

I had app_server crash on me because of an uncaught allocation
exception. I don't know if this will fix it but it's better to try to
survive even if it may result in some UI glitches.

Change-Id: I09dd2a7e6ff63d52f51389d7418d1a1d1810af00
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1720
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Adrien Destugues 2019-08-15 18:01:32 +02:00 committed by waddlesplash
parent fe08f0b3d0
commit b5be469eee
3 changed files with 18 additions and 5 deletions

View File

@ -428,7 +428,7 @@ struct node {
void init(const BRect& r, int32 maxPointers) void init(const BRect& r, int32 maxPointers)
{ {
rect = r; rect = r;
pointers = new node*[maxPointers]; pointers = new(std::nothrow) node*[maxPointers];
in_degree = 0; in_degree = 0;
next_pointer = 0; next_pointer = 0;
} }
@ -490,6 +490,8 @@ DrawingEngine::CopyRegion(/*const*/ BRegion* region, int32 xOffset,
BStackOrHeapArray<node, 64> nodes(count); BStackOrHeapArray<node, 64> nodes(count);
for (int32 i= 0; i < count; i++) { for (int32 i= 0; i < count; i++) {
nodes[i].init(region->RectAt(i), count); nodes[i].init(region->RectAt(i), count);
if (nodes[i].pointers == NULL)
return;
} }
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
@ -551,8 +553,11 @@ DrawingEngine::CopyRegion(/*const*/ BRegion* region, int32 xOffset,
clipping_rect* sortedRectList = NULL; clipping_rect* sortedRectList = NULL;
int32 nextSortedIndex = 0; int32 nextSortedIndex = 0;
if (fAvailableHWAccleration & HW_ACC_COPY_REGION) if (fAvailableHWAccleration & HW_ACC_COPY_REGION) {
sortedRectList = new clipping_rect[count]; sortedRectList = new(std::nothrow) clipping_rect[count];
if (sortedRectList == NULL)
return;
}
while (!inDegreeZeroNodes.empty()) { while (!inDegreeZeroNodes.empty()) {
node* n = inDegreeZeroNodes.top(); node* n = inDegreeZeroNodes.top();

View File

@ -586,8 +586,10 @@ HWInterface::_DrawCursor(IntRect area) const
// that has the cursor blended on top of it // that has the cursor blended on top of it
// blending buffer // blending buffer
uint8* buffer = new uint8[width * height * 4]; uint8* buffer = new(std::nothrow) uint8[width * height * 4];
// TODO: cache this buffer // TODO: cache this buffer
if (buffer == NULL)
return;
// offset into back buffer // offset into back buffer
uint8* src = (uint8*)backBuffer->Bits(); uint8* src = (uint8*)backBuffer->Bits();
@ -1085,6 +1087,10 @@ HWInterface::_AdoptDragBitmap(const ServerBitmap* bitmap, const BPoint& offset)
BRect cursorBounds = fCursorAndDragBitmap->Bounds(); BRect cursorBounds = fCursorAndDragBitmap->Bounds();
fCursorAreaBackup = new buffer_clip(cursorBounds.IntegerWidth() + 1, fCursorAreaBackup = new buffer_clip(cursorBounds.IntegerWidth() + 1,
cursorBounds.IntegerHeight() + 1); cursorBounds.IntegerHeight() + 1);
if (fCursorAreaBackup->buffer == NULL) {
delete fCursorAreaBackup;
fCursorAreaBackup = NULL;
}
} }
_DrawCursor(_CursorFrame()); _DrawCursor(_CursorFrame());
} }

View File

@ -18,6 +18,8 @@
#include <video_overlay.h> #include <video_overlay.h>
#include <new>
#include "IntRect.h" #include "IntRect.h"
#include "MultiLocker.h" #include "MultiLocker.h"
#include "ServerCursor.h" #include "ServerCursor.h"
@ -224,7 +226,7 @@ protected:
{ {
bpr = width * 4; bpr = width * 4;
if (bpr > 0 && height > 0) if (bpr > 0 && height > 0)
buffer = new uint8[bpr * height]; buffer = new(std::nothrow) uint8[bpr * height];
else else
buffer = NULL; buffer = NULL;
left = 0; left = 0;