Handle some out of memory situations a bit more gracefully.

master
Nicky 2013-02-07 23:51:49 +01:00
parent 6a200589b3
commit 838d611bcf
3 changed files with 48 additions and 2 deletions

View File

@ -964,6 +964,11 @@ BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
if( !new_buffer )
return FALSE;
// </FS:ND>
// Horizontal
for( S32 row = 0; row < new_height; row++ )
{
@ -980,6 +985,11 @@ BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
// allocate new image data, will delete old data
U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
if( !new_buffer )
return FALSE;
// </FS:ND>
for( S32 row = 0; row < new_height; row++ )
{
if (row < old_height)

View File

@ -338,6 +338,11 @@ BOOL LLImageTGA::decode(LLImageRaw* raw_image, F32 decode_time)
raw_image->resize(getWidth(), getHeight(), getComponents());
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
if( raw_image->isBufferInvalid() )
return FALSE;
// </FS:ND>
if( (getComponents() != 1) &&
(getComponents() != 3) &&
(getComponents() != 4) )
@ -368,6 +373,11 @@ BOOL LLImageTGA::decode(LLImageRaw* raw_image, F32 decode_time)
BOOL LLImageTGA::decodeTruecolor( LLImageRaw* raw_image, BOOL rle, BOOL flipped )
{
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
if( !raw_image || raw_image->isBufferInvalid() )
return FALSE;
// </FS:ND>
BOOL success = FALSE;
BOOL alpha_opaque = FALSE;
if( rle )
@ -519,6 +529,11 @@ void LLImageTGA::decodeColorMapPixel32( U8* dst, const U8* src )
BOOL LLImageTGA::decodeColorMap( LLImageRaw* raw_image, BOOL rle, BOOL flipped )
{
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
if( !raw_image || raw_image->isBufferInvalid() )
return FALSE;
// </FS:ND>
// If flipped, origin is the top left. Need to reverse the order of the rows.
// Otherwise the origin is the bottom left.

View File

@ -143,7 +143,17 @@ bool LLImageDecodeThread::ImageRequest::processRequest()
mFormattedImage->getHeight(),
mFormattedImage->getComponents());
}
done = mFormattedImage->decode(mDecodedImageRaw, decode_time_slice); // 1ms
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
// done = mFormattedImage->decode(mDecodedImageRaw, decode_time_slice); // 1ms
if( mDecodedImageRaw && !mDecodedImageRaw->isBufferInvalid() )
done = mFormattedImage->decode(mDecodedImageRaw, decode_time_slice); // 1ms
else
done = false;
// </FS:ND>
mDecodedRaw = done;
}
if (done && mNeedsAux && !mDecodedAux && mFormattedImage.notNull())
@ -155,7 +165,18 @@ bool LLImageDecodeThread::ImageRequest::processRequest()
mFormattedImage->getHeight(),
1);
}
done = mFormattedImage->decodeChannels(mDecodedImageAux, decode_time_slice, 4, 4); // 1ms
// <FS:ND> Handle out of memory situations a bit more graceful than a crash
// done = mFormattedImage->decodeChannels(mDecodedImageAux, decode_time_slice, 4, 4); // 1ms
if( mDecodedImageAux && !mDecodedImageAux->isBufferInvalid() )
done = mFormattedImage->decodeChannels(mDecodedImageAux, decode_time_slice, 4, 4); // 1ms
else
done = false;
// </FS:ND>
mDecodedAux = done;
}