diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 86f006df30..884fc1f6d5 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -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()); + // Handle out of memory situations a bit more graceful than a crash + if( !new_buffer ) + return FALSE; + // + // 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()); + // Handle out of memory situations a bit more graceful than a crash + if( !new_buffer ) + return FALSE; + // + for( S32 row = 0; row < new_height; row++ ) { if (row < old_height) diff --git a/indra/llimage/llimagetga.cpp b/indra/llimage/llimagetga.cpp index e2e4aee5e7..70ee4f78b6 100644 --- a/indra/llimage/llimagetga.cpp +++ b/indra/llimage/llimagetga.cpp @@ -338,6 +338,11 @@ BOOL LLImageTGA::decode(LLImageRaw* raw_image, F32 decode_time) raw_image->resize(getWidth(), getHeight(), getComponents()); + // Handle out of memory situations a bit more graceful than a crash + if( raw_image->isBufferInvalid() ) + return FALSE; + // + 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 ) { + // Handle out of memory situations a bit more graceful than a crash + if( !raw_image || raw_image->isBufferInvalid() ) + return FALSE; + // + 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 ) { + // Handle out of memory situations a bit more graceful than a crash + if( !raw_image || raw_image->isBufferInvalid() ) + return FALSE; + // + // If flipped, origin is the top left. Need to reverse the order of the rows. // Otherwise the origin is the bottom left. diff --git a/indra/llimage/llimageworker.cpp b/indra/llimage/llimageworker.cpp index fea77a1c86..54bf242415 100644 --- a/indra/llimage/llimageworker.cpp +++ b/indra/llimage/llimageworker.cpp @@ -143,7 +143,17 @@ bool LLImageDecodeThread::ImageRequest::processRequest() mFormattedImage->getHeight(), mFormattedImage->getComponents()); } - done = mFormattedImage->decode(mDecodedImageRaw, decode_time_slice); // 1ms + + // 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; + // + 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 + + // 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; + + // + mDecodedAux = done; }