From 80be4c1d2d73982ea2df6dd7ef3fc3465416c882 Mon Sep 17 00:00:00 2001 From: Steven Bennetts Date: Tue, 12 Aug 2008 17:29:50 +0000 Subject: QAR-767 Combined maint-render-7 and maint-viewer-9 merge merge release@93398 viewer-merge-1@94007 -> release dataserver-is-deprecated --- indra/llimage/llimagejpeg.cpp | 33 ++++++++++++++++++++++++++------- indra/llimage/llimagejpeg.h | 4 ++-- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'indra/llimage') diff --git a/indra/llimage/llimagejpeg.cpp b/indra/llimage/llimagejpeg.cpp index 1bddd7a051..aab19aa261 100644 --- a/indra/llimage/llimagejpeg.cpp +++ b/indra/llimage/llimagejpeg.cpp @@ -35,6 +35,7 @@ #include "llerror.h" +jmp_buf LLImageJPEG::sSetjmpBuffer ; LLImageJPEG::LLImageJPEG(S32 quality) : LLImageFormatted(IMG_CODEC_JPEG), @@ -42,8 +43,6 @@ LLImageJPEG::LLImageJPEG(S32 quality) mOutputBufferSize( 0 ), mEncodeQuality( quality ) // on a scale from 1 to 100 { - // Including in initializer list above generates warning on VC2005 - memset(mSetjmpBuffer, 0, sizeof(mSetjmpBuffer)); } LLImageJPEG::~LLImageJPEG() @@ -78,7 +77,16 @@ BOOL LLImageJPEG::updateData() jerr.error_exit = &LLImageJPEG::errorExit; // Error exit handler: does not return to caller jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message - + + // + //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error + //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao + // + if(setjmp(sSetjmpBuffer)) + { + jpeg_destroy_decompress(&cinfo); + return FALSE; + } try { // Now we can initialize the JPEG decompression object. @@ -210,7 +218,15 @@ BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time) jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message - + // + //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error + //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao + // + if(setjmp(sSetjmpBuffer)) + { + jpeg_destroy_decompress(&cinfo); + return FALSE; + } try { // Now we can initialize the JPEG decompression object. @@ -404,7 +420,7 @@ void LLImageJPEG::errorExit( j_common_ptr cinfo ) jpeg_destroy(cinfo); // Return control to the setjmp point - throw 1; + longjmp(sSetjmpBuffer, 1) ; } // Decide whether to emit a trace or warning message. @@ -502,8 +518,11 @@ BOOL LLImageJPEG::encode( const LLImageRaw* raw_image, F32 encode_time ) jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message - // Establish the setjmp return context mSetjmpBuffer. Used by library to abort. - if( setjmp(mSetjmpBuffer) ) + // + //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error + //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao + // + if( setjmp(sSetjmpBuffer) ) { // If we get here, the JPEG code has signaled an error. // We need to clean up the JPEG object, close the input file, and return. diff --git a/indra/llimage/llimagejpeg.h b/indra/llimage/llimagejpeg.h index 36d3454d4b..85e69d9b8f 100644 --- a/indra/llimage/llimagejpeg.h +++ b/indra/llimage/llimagejpeg.h @@ -84,8 +84,8 @@ protected: S32 mOutputBufferSize; // bytes in mOuputBuffer S32 mEncodeQuality; // on a scale from 1 to 100 - - jmp_buf mSetjmpBuffer; // To allow the library to abort. +private: + static jmp_buf sSetjmpBuffer; // To allow the library to abort. }; #endif // LL_LLIMAGEJPEG_H -- cgit v1.2.3