diff --git a/irr/src/CImageLoaderPNG.cpp b/irr/src/CImageLoaderPNG.cpp index 42cfc51d2..69a283890 100644 --- a/irr/src/CImageLoaderPNG.cpp +++ b/irr/src/CImageLoaderPNG.cpp @@ -18,14 +18,20 @@ namespace video // PNG function for error handling static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) { - os::Printer::log("PNG fatal error", msg, ELL_ERROR); + io::IReadFile *file = reinterpret_cast(png_get_error_ptr(png_ptr)); + std::string logmsg = std::string("PNG fatal error for ") + + file->getFileName().c_str() + ": " + msg; + os::Printer::log(logmsg.c_str(), ELL_ERROR); longjmp(png_jmpbuf(png_ptr), 1); } // PNG function for warning handling static void png_cpexcept_warn(png_structp png_ptr, png_const_charp msg) { - os::Printer::log("PNG warning", msg, ELL_WARNING); + io::IReadFile *file = reinterpret_cast(png_get_error_ptr(png_ptr)); + std::string logmsg = std::string("PNG warning for ") + + file->getFileName().c_str() + ": " + msg; + os::Printer::log(logmsg.c_str(), ELL_WARNING); } // PNG function for file reading @@ -88,7 +94,7 @@ IImage *CImageLoaderPng::loadImage(io::IReadFile *file) const // Allocate the png read struct png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, - NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warn); + file, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warn); if (!png_ptr) { os::Printer::log("LOAD PNG: Internal PNG create read struct failure", file->getFileName(), ELL_ERROR); return 0; diff --git a/irr/src/CImageWriterPNG.cpp b/irr/src/CImageWriterPNG.cpp index 1c8a840ca..7bd3065c6 100644 --- a/irr/src/CImageWriterPNG.cpp +++ b/irr/src/CImageWriterPNG.cpp @@ -25,14 +25,20 @@ IImageWriter *createImageWriterPNG() // PNG function for error handling static void png_cpexcept_error(png_structp png_ptr, png_const_charp msg) { - os::Printer::log("PNG fatal error", msg, ELL_ERROR); + io::IWriteFile *file = reinterpret_cast(png_get_error_ptr(png_ptr)); + std::string logmsg = std::string("PNG fatal error for ") + + file->getFileName().c_str() + ": " + msg; + os::Printer::log(logmsg.c_str(), ELL_ERROR); longjmp(png_jmpbuf(png_ptr), 1); } // PNG function for warning handling static void png_cpexcept_warning(png_structp png_ptr, png_const_charp msg) { - os::Printer::log("PNG warning", msg, ELL_WARNING); + io::IWriteFile *file = reinterpret_cast(png_get_error_ptr(png_ptr)); + std::string logmsg = std::string("PNG warning for ") + + file->getFileName().c_str() + ": " + msg; + os::Printer::log(logmsg.c_str(), ELL_WARNING); } // PNG function for file writing @@ -66,7 +72,7 @@ bool CImageWriterPNG::writeImage(io::IWriteFile *file, IImage *image, u32 param) // Allocate the png write struct png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warning); + file, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warning); if (!png_ptr) { os::Printer::log("PNGWriter: Internal PNG create write struct failure", file->getFileName(), ELL_ERROR); return false; diff --git a/irr/src/CNullDriver.cpp b/irr/src/CNullDriver.cpp index 347569e6a..92450e5d7 100644 --- a/irr/src/CNullDriver.cpp +++ b/irr/src/CNullDriver.cpp @@ -983,6 +983,11 @@ IImage *CNullDriver::createImageFromFile(io::IReadFile *file) continue; file->seek(0); // reset file position which might have changed due to previous loadImage calls + // avoid warnings if extension is wrong + if (!SurfaceLoader[i]->isALoadableFileFormat(file)) + continue; + + file->seek(0); if (IImage *image = SurfaceLoader[i]->loadImage(file)) return image; } diff --git a/src/client/client.cpp b/src/client/client.cpp index 789a37c36..ca3f91e78 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -799,7 +799,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, video::IVideoDriver *vdrv = m_rendering_engine->get_video_driver(); io::IReadFile *rfile = irrfs->createMemoryReadFile( - data.c_str(), data.size(), "_tempreadfile"); + data.c_str(), data.size(), filename.c_str()); FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file."); diff --git a/src/client/imagesource.cpp b/src/client/imagesource.cpp index d401e98ed..4bcfb9804 100644 --- a/src/client/imagesource.cpp +++ b/src/client/imagesource.cpp @@ -1704,7 +1704,7 @@ bool ImageSource::generateImagePart(std::string_view part_of_name, auto *device = RenderingEngine::get_raw_device(); auto *fs = device->getFileSystem(); auto *vd = device->getVideoDriver(); - auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "__temp_png"); + auto *memfile = fs->createMemoryReadFile(png.data(), png.size(), "[png_tmpfile"); video::IImage* pngimg = vd->createImageFromFile(memfile); memfile->drop();