From 75149be061fab7c8d7ce0e24e0c9ad0e52d0dd5b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 13 Jul 2016 14:19:26 -0400 Subject: MAINT-5011: Wrap thrown png_const_charp in new PngError class derived from std::runtime_error. --- indra/llimage/llpngwrapper.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index aad139f570..4292f29acc 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -31,6 +31,13 @@ #include "llimage.h" #include "llpngwrapper.h" +#include + +struct PngError: public std::runtime_error +{ + PngError(png_const_charp msg): std::runtime_error(msg) {} +}; + // --------------------------------------------------------------------------- // LLPngWrapper // --------------------------------------------------------------------------- @@ -75,11 +82,10 @@ BOOL LLPngWrapper::isValidPng(U8* src) } // Called by the libpng library when a fatal encoding or decoding error -// occurs. We simply throw the error message and let our try/catch -// block clean up. +// occurs. We throw PngError and let our try/catch block clean up. void LLPngWrapper::errorHandler(png_structp png_ptr, png_const_charp msg) { - throw msg; + throw PngError(msg); } // Called by the libpng library when reading (decoding) the PNG file. We @@ -129,7 +135,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf this, &errorHandler, NULL); if (mReadPngPtr == NULL) { - throw "Problem creating png read structure"; + throw PngError("Problem creating png read structure"); } // Allocate/initialize the memory for image information. @@ -187,9 +193,9 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf mFinalSize = dataPtr.mOffset; } - catch (png_const_charp msg) + catch (const PngError& msg) { - mErrorMessage = msg; + mErrorMessage = msg.what(); releaseResources(); return (FALSE); } @@ -288,14 +294,14 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) if (mColorType == -1) { - throw "Unsupported image: unexpected number of channels"; + throw PngError("Unsupported image: unexpected number of channels"); } mWritePngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &errorHandler, NULL); if (!mWritePngPtr) { - throw "Problem creating png write structure"; + throw PngError("Problem creating png write structure"); } mWriteInfoPtr = png_create_info_struct(mWritePngPtr); @@ -339,9 +345,9 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) png_write_end(mWritePngPtr, mWriteInfoPtr); mFinalSize = dataPtr.mOffset; } - catch (png_const_charp msg) + catch (const PngError& msg) { - mErrorMessage = msg; + mErrorMessage = msg.what(); releaseResources(); return (FALSE); } -- cgit v1.2.3 From 636ce117bb1b3bda30ff725d41b50ed2c48e4bf0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 14 Jul 2016 10:35:56 -0400 Subject: MAINT-5011: Per NickyD, put PngError in anonymous namespace. --- indra/llimage/llpngwrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 4292f29acc..531859cbc9 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -33,10 +33,12 @@ #include +namespace { struct PngError: public std::runtime_error { PngError(png_const_charp msg): std::runtime_error(msg) {} }; +} // anonymous namespace // --------------------------------------------------------------------------- // LLPngWrapper -- cgit v1.2.3 From 9c49a6c91dd9b5bbe811fcd91d8992ed6bac33e7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 19 Jul 2016 16:25:25 -0400 Subject: MAINT-5011: Introduce LLException base class for viewer exceptions. This also introduces LLContinueError for exceptions which should interrupt some part of viewer processing (e.g. the current coroutine) but should attempt to let the viewer session proceed. Derive all existing viewer exception classes from LLException rather than from std::runtime_error or std::logic_error. Use BOOST_THROW_EXCEPTION() rather than plain 'throw' to enrich the thrown exception with source file, line number and containing function. --- indra/llimage/llpngwrapper.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 531859cbc9..0b7d4c717f 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -31,12 +31,13 @@ #include "llimage.h" #include "llpngwrapper.h" -#include +#include "llexception.h" +#include namespace { -struct PngError: public std::runtime_error +struct PngError: public LLException { - PngError(png_const_charp msg): std::runtime_error(msg) {} + PngError(png_const_charp msg): LLException(msg) {} }; } // anonymous namespace @@ -87,7 +88,7 @@ BOOL LLPngWrapper::isValidPng(U8* src) // occurs. We throw PngError and let our try/catch block clean up. void LLPngWrapper::errorHandler(png_structp png_ptr, png_const_charp msg) { - throw PngError(msg); + BOOST_THROW_EXCEPTION(PngError(msg)); } // Called by the libpng library when reading (decoding) the PNG file. We @@ -137,7 +138,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf this, &errorHandler, NULL); if (mReadPngPtr == NULL) { - throw PngError("Problem creating png read structure"); + BOOST_THROW_EXCEPTION(PngError("Problem creating png read structure")); } // Allocate/initialize the memory for image information. @@ -296,14 +297,14 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) if (mColorType == -1) { - throw PngError("Unsupported image: unexpected number of channels"); + BOOST_THROW_EXCEPTION(PngError("Unsupported image: unexpected number of channels")); } mWritePngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &errorHandler, NULL); if (!mWritePngPtr) { - throw PngError("Problem creating png write structure"); + BOOST_THROW_EXCEPTION(PngError("Problem creating png write structure")); } mWriteInfoPtr = png_create_info_struct(mWritePngPtr); -- cgit v1.2.3 From 5e9d2f57c82a57307a48afea09aa539b9fa80abf Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Aug 2016 11:36:24 -0400 Subject: MAINT-5011: Use LLTHROW() instead of plain BOOST_THROW_EXCEPTION(). A level of preprocessor indirection lets us later change the implementation if desired. --- indra/llimage/llpngwrapper.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 0b7d4c717f..640eda7b01 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -32,7 +32,6 @@ #include "llpngwrapper.h" #include "llexception.h" -#include namespace { struct PngError: public LLException @@ -88,7 +87,7 @@ BOOL LLPngWrapper::isValidPng(U8* src) // occurs. We throw PngError and let our try/catch block clean up. void LLPngWrapper::errorHandler(png_structp png_ptr, png_const_charp msg) { - BOOST_THROW_EXCEPTION(PngError(msg)); + LLTHROW(PngError(msg)); } // Called by the libpng library when reading (decoding) the PNG file. We @@ -138,7 +137,7 @@ BOOL LLPngWrapper::readPng(U8* src, S32 dataSize, LLImageRaw* rawImage, ImageInf this, &errorHandler, NULL); if (mReadPngPtr == NULL) { - BOOST_THROW_EXCEPTION(PngError("Problem creating png read structure")); + LLTHROW(PngError("Problem creating png read structure")); } // Allocate/initialize the memory for image information. @@ -297,14 +296,14 @@ BOOL LLPngWrapper::writePng(const LLImageRaw* rawImage, U8* dest) if (mColorType == -1) { - BOOST_THROW_EXCEPTION(PngError("Unsupported image: unexpected number of channels")); + LLTHROW(PngError("Unsupported image: unexpected number of channels")); } mWritePngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &errorHandler, NULL); if (!mWritePngPtr) { - BOOST_THROW_EXCEPTION(PngError("Problem creating png write structure")); + LLTHROW(PngError("Problem creating png write structure")); } mWriteInfoPtr = png_create_info_struct(mWritePngPtr); -- cgit v1.2.3 From 83eb9600631fcb98275b8d3db736f692fd5e6e1c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Aug 2016 15:47:08 -0400 Subject: MAINT-5011: Derive image-load exceptions from LLContinueError. Failure to load an image shouldn't crash the whole viewer. --- indra/llimage/llpngwrapper.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llpngwrapper.cpp b/indra/llimage/llpngwrapper.cpp index 640eda7b01..da289ea889 100644 --- a/indra/llimage/llpngwrapper.cpp +++ b/indra/llimage/llpngwrapper.cpp @@ -34,9 +34,10 @@ #include "llexception.h" namespace { -struct PngError: public LLException +// Failure to load an image shouldn't crash the whole viewer. +struct PngError: public LLContinueError { - PngError(png_const_charp msg): LLException(msg) {} + PngError(png_const_charp msg): LLContinueError(msg) {} }; } // anonymous namespace -- cgit v1.2.3 From 53f9fbcfb7090372b781e1b73c1458174cc7c761 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Tue, 6 Sep 2016 09:11:10 -0400 Subject: add run time error checking to LLImageRaw::scale --- indra/llimage/llimage.cpp | 93 +++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 51 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 91fa8c6ad1..02f1b223c2 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -1401,7 +1401,12 @@ void LLImageRaw::copyScaled( LLImageRaw* src ) bool LLImageRaw::scale( S32 new_width, S32 new_height, bool scale_image_data ) { - llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) ); + S32 components = getComponents(); + if (! ((1 == components) || (3 == components) || (4 == components) ) + { + LL_WARNS() << "Invalid getComponents value (" << components << ")" << LL_ENDL; + return false; + } S32 old_width = getWidth(); S32 old_height = getHeight(); @@ -1415,67 +1420,53 @@ bool LLImageRaw::scale( S32 new_width, S32 new_height, bool scale_image_data ) if (scale_image_data) { - /* - S32 temp_data_size = old_width * new_height * getComponents(); - llassert_always(temp_data_size > 0); - std::vector temp_buffer(temp_data_size); - - // Vertical - for( S32 col = 0; col < old_width; col++ ) - { - copyLineScaled( getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), old_height, new_height, old_width, old_width ); - } - - deleteData(); + S32 new_data_size = new_width * new_height * components; - U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); + if (new_data_size > 0) + { + U8 *new_data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), new_data_size); + if(NULL == new_data) + { + return false; + } - // Horizontal - for( S32 row = 0; row < new_height; row++ ) - { - copyLineScaled( &temp_buffer[0] + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 ); - } - */ - - S32 new_data_size = new_width * new_height * getComponents(); - llassert_always(new_data_size > 0); - - U8 *new_data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), new_data_size); - if(NULL == new_data) - { - return false; + bilinear_scale(getData(), old_width, old_height, components, old_width*components, new_data, new_width, new_height, components, new_width*components); + setDataAndSize(new_data, new_width, new_height, components); } - - bilinear_scale(getData(), old_width, old_height, getComponents(), old_width*getComponents(), new_data, new_width, new_height, getComponents(), new_width*getComponents()); - setDataAndSize(new_data, new_width, new_height, getComponents()); } else { // copy out existing image data - S32 temp_data_size = old_width * old_height * getComponents(); + S32 temp_data_size = old_width * old_height * components; std::vector temp_buffer(temp_data_size); memcpy(&temp_buffer[0], getData(), temp_data_size); // allocate new image data, will delete old data - U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); - - for( S32 row = 0; row < new_height; row++ ) - { - if (row < old_height) - { - memcpy(new_buffer + (new_width * row * getComponents()), &temp_buffer[0] + (old_width * row * getComponents()), getComponents() * llmin(old_width, new_width)); - if (old_width < new_width) - { - // pad out rest of row with black - memset(new_buffer + (getComponents() * ((new_width * row) + old_width)), 0, getComponents() * (new_width - old_width)); - } - } - else - { - // pad remaining rows with black - memset(new_buffer + (new_width * row * getComponents()), 0, new_width * getComponents()); - } - } + U8* new_buffer = allocateDataSize(new_width, new_height, components); + + if (!new_buffer) + { + LL_WARNS() << "Failed to allocate new image data buffer" << LL_ENDL; + return false; + } + + for( S32 row = 0; row < new_height; row++ ) + { + if (row < old_height) + { + memcpy(new_buffer + (new_width * row * components), &temp_buffer[0] + (old_width * row * components), components * llmin(old_width, new_width)); + if (old_width < new_width) + { + // pad out rest of row with black + memset(new_buffer + (components * ((new_width * row) + old_width)), 0, components * (new_width - old_width)); + } + } + else + { + // pad remaining rows with black + memset(new_buffer + (new_width * row * components), 0, new_width * components); + } + } } return true ; -- cgit v1.2.3 From 8c86c594be7b7898ac6e622c505181cf5b000da6 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Tue, 6 Sep 2016 11:01:02 -0400 Subject: paren fix --- indra/llimage/llimage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 02f1b223c2..f331c533fd 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -1402,7 +1402,7 @@ void LLImageRaw::copyScaled( LLImageRaw* src ) bool LLImageRaw::scale( S32 new_width, S32 new_height, bool scale_image_data ) { S32 components = getComponents(); - if (! ((1 == components) || (3 == components) || (4 == components) ) + if (! ((1 == components) || (3 == components) || (4 == components) )) { LL_WARNS() << "Invalid getComponents value (" << components << ")" << LL_ENDL; return false; -- cgit v1.2.3