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
This commit is contained in:
cutealien 2021-06-11 15:09:02 +00:00
parent 224d7c5e2c
commit e7143ef977
3 changed files with 9 additions and 10 deletions

@ -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)

@ -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

@ -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_
};