diff --git a/src/kits/interface/Bitmap.cpp b/src/kits/interface/Bitmap.cpp index b0e43c1c98..354e1e2708 100644 --- a/src/kits/interface/Bitmap.cpp +++ b/src/kits/interface/Bitmap.cpp @@ -949,12 +949,13 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags, if (!bounds.IsValid() || !bitmaps_support_space(colorSpace, NULL)) { error = B_BAD_VALUE; } else { - // bounds is in floats and might be valid but much larger than what we can handle - // the size could not be expressed in int32 + // bounds is in floats and might be valid but much larger than what we + // can handle the size could not be expressed in int32 double realSize = bounds.Width() * bounds.Height(); if (realSize > (double)(INT_MAX / 4)) { - fprintf(stderr, "bitmap bounds is much too large: BRect(%.1f, %.1f, %.1f, %.1f)\n", - bounds.left, bounds.top, bounds.right, bounds.bottom); + fprintf(stderr, "bitmap bounds is much too large: " + "BRect(%.1f, %.1f, %.1f, %.1f)\n", + bounds.left, bounds.top, bounds.right, bounds.bottom); error = B_BAD_VALUE; } } @@ -1052,16 +1053,28 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags, } fInitError = error; - // TODO: on success, handle clearing to white if the flags say so. Needs to be - // dependent on color space. if (fInitError == B_OK) { if (flags & B_BITMAP_ACCEPTS_VIEWS) { - fWindow = new BWindow(Bounds(), fServerToken); - // A BWindow starts life locked and is unlocked - // in Show(), but this window is never shown and - // it's message loop is never started. - fWindow->Unlock(); + fWindow = new(std::nothrow) BWindow(Bounds(), fServerToken); + if (fWindow) { + // A BWindow starts life locked and is unlocked + // in Show(), but this window is never shown and + // it's message loop is never started. + fWindow->Unlock(); + } else + fInitError = B_NO_MEMORY; + } + // clear to white if the flags say so. + if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) { + if (fColorSpace == B_CMAP8) { + // "255" is the "transparent magic" index for B_CMAP8 bitmaps + // use the correct index for "white" + memset(fBasePointer, 65, fSize); + } else { + // should work for most colorspaces + memset(fBasePointer, 0xff, fSize); + } } } } diff --git a/src/servers/app/BitmapManager.cpp b/src/servers/app/BitmapManager.cpp index 4d14717a49..08c9d396f3 100644 --- a/src/servers/app/BitmapManager.cpp +++ b/src/servers/app/BitmapManager.cpp @@ -188,16 +188,8 @@ BitmapManager::CreateBitmap(ClientMemoryAllocator* allocator, if (success) { bitmap->fBuffer = buffer; bitmap->fToken = gTokenSpace.NewToken(kBitmapToken, bitmap); - - if (flags & (B_BITMAP_CLEAR_TO_WHITE | B_BITMAP_ACCEPTS_VIEWS)) { - if (space == B_CMAP8) { - // "255" is the "transparent magic" index for B_CMAP8 bitmaps - memset(bitmap->Bits(), 65, bitmap->BitsLength()); - } else { - // should work for most colorspaces - memset(bitmap->Bits(), 0xff, bitmap->BitsLength()); - } - } + // NOTE: the client handles clearing to white in case the flags + // indicate this is needed } else { // Allocation failed for buffer or bitmap list delete bitmap;