From e7143ef977032a5d4e9da44e33a6ccc7f1cb9f2b Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 11 Jun 2021 15:09:02 +0000 Subject: [PATCH] Make CImageLoaderJPG thread safe. Thanks @ Edoardo Lolletti for report and patch (patch #324) Replace a static variable which was used in error-reporting but wasn't thread-safe. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6220 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 1 + source/Irrlicht/CImageLoaderJPG.cpp | 15 ++++++++------- source/Irrlicht/CImageLoaderJPG.h | 3 --- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/changes.txt b/changes.txt index 8c00b5b..bf0286f 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,6 @@ -------------------------- Changes in 1.9 (not yet released) +- Make CImageLoaderJPG thread safe. Thanks @ Edoardo Lolletti for report and patch (patch #324) - Add ETCF_SUPPORT_VERTEXT_TEXTURE flag which can be used to enable vertex texture sampling support in Direct3D 9. Note that this was enabled for a long time in 1.9 svn, but is now disabled by default. - CGUIListBox now serializes the state of "Selected". Feature wish by chronologicaldot (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=2&t=52719) diff --git a/source/Irrlicht/CImageLoaderJPG.cpp b/source/Irrlicht/CImageLoaderJPG.cpp index 6b51bd9..72ba484 100644 --- a/source/Irrlicht/CImageLoaderJPG.cpp +++ b/source/Irrlicht/CImageLoaderJPG.cpp @@ -16,11 +16,6 @@ namespace irr namespace video { -#ifdef _IRR_COMPILE_WITH_LIBJPEG_ -// Static members -io::path CImageLoaderJPG::Filename; -#endif - //! constructor CImageLoaderJPG::CImageLoaderJPG() { @@ -56,6 +51,9 @@ bool CImageLoaderJPG::isALoadableFileExtension(const io::path& filename) const // for longjmp, to return to caller on a fatal error jmp_buf setjmp_buffer; + + // for having access to the filename when printing the error messages + core::stringc* filename; }; void CImageLoaderJPG::init_source (j_decompress_ptr cinfo) @@ -113,7 +111,9 @@ void CImageLoaderJPG::output_message(j_common_ptr cinfo) c8 temp1[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, temp1); core::stringc errMsg("JPEG FATAL ERROR in "); - errMsg += core::stringc(Filename); + + irr_jpeg_error_mgr* myerr = (irr_jpeg_error_mgr*)cinfo->err; + errMsg += *myerr->filename; os::Printer::log(errMsg.c_str(),temp1, ELL_ERROR); } #endif // _IRR_COMPILE_WITH_LIBJPEG_ @@ -144,7 +144,7 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const if (!file) return 0; - Filename = file->getFileName(); + core::stringc filename = file->getFileName(); u8 **rowPtr=0; u8* input = new u8[file->getSize()]; @@ -162,6 +162,7 @@ IImage* CImageLoaderJPG::loadImage(io::IReadFile* file) const cinfo.err = jpeg_std_error(&jerr.pub); cinfo.err->error_exit = error_exit; cinfo.err->output_message = output_message; + jerr.filename = &filename; // compatibility fudge: // we need to use setjmp/longjmp for error handling as gcc-linux diff --git a/source/Irrlicht/CImageLoaderJPG.h b/source/Irrlicht/CImageLoaderJPG.h index 1726e26..2360409 100644 --- a/source/Irrlicht/CImageLoaderJPG.h +++ b/source/Irrlicht/CImageLoaderJPG.h @@ -100,9 +100,6 @@ private: data has been read. Often a no-op. */ static void term_source (j_decompress_ptr cinfo); - // Copy filename to have it around for error-messages - static io::path Filename; - #endif // _IRR_COMPILE_WITH_LIBJPEG_ };