diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index e12e0a307d..7cbc1b4d01 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -1017,7 +1017,15 @@ int F3DStarter::Start(int argc, char** argv) } else { - window.renderToImage(this->Internals->AppOptions.NoBackground).save(output); + try + { + window.renderToImage(this->Internals->AppOptions.NoBackground).save(output); + } + catch (const f3d::image::write_exception& ex) + { + f3d::log::error("Could not write output: ", ex.what()); + return EXIT_FAILURE; + } f3d::log::error("Reference image ", reference, " does not exist, current rendering has been outputted to ", output, ".\n"); @@ -1048,7 +1056,15 @@ int F3DStarter::Start(int argc, char** argv) f3d::log::error("Current rendering difference with reference image: ", error, " is higher than the threshold of ", threshold, ".\n"); - img.save(output); + try + { + img.save(output); + } + catch (const f3d::image::write_exception& ex) + { + f3d::log::error("Could not write output: ", ex.what()); + return EXIT_FAILURE; + } } return EXIT_FAILURE; } @@ -1083,7 +1099,16 @@ int F3DStarter::Start(int argc, char** argv) } else { - img.save(output); + try + { + img.save(output); + } + catch (const f3d::image::write_exception& ex) + { + f3d::log::error("Could not write output: ", ex.what()); + return EXIT_FAILURE; + } + f3d::log::debug("Output image saved to ", output); } diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 0d1f0725c6..f03d6808bb 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -1174,6 +1174,10 @@ if(NOT WIN32) f3d_test(NAME TestColorMapTooLong DATA dragon.vtu ARGS --colormap-file=${_f3d_test_invalid_folder}/file.ext --scalar-coloring REGEXP "File name too long" NO_BASELINE) f3d_test(NAME TestScreenshotTooLong DATA suzanne.ply ARGS --screenshot-filename=${_f3d_test_invalid_folder}/file.ext --interaction-test-play=${F3D_SOURCE_DIR}/testing/recordings/TestScreenshot.log REGEXP "File name too long" NO_BASELINE) f3d_test(NAME TestInputTooLong ARGS --input=${_f3d_test_invalid_folder}/file.ext REGEXP "File name too long" NO_BASELINE) + f3d_test(NAME TestReferenceTooLong DATA suzanne.ply ARGS --output=file.png --reference=${_f3d_test_invalid_folder}/file.ext REGEXP "File name too long" NO_BASELINE) + f3d_test(NAME TestOutputTooLong DATA suzanne.ply ARGS --output=${_f3d_test_invalid_folder}/file.ext REGEXP "File name too long" NO_BASELINE) + f3d_test(NAME TestOutputWithReferenceTooLong DATA suzanne.ply ARGS --reference=file.png --output=${_f3d_test_invalid_folder}/file.ext REGEXP "File name too long" NO_BASELINE) + f3d_test(NAME TestOutputWithExistingReferenceTooLong DATA suzanne.ply ARGS --reference=${F3D_SOURCE_DIR}/testing/data/world.png --output=${_f3d_test_invalid_folder}/file.ext REGEXP "File name too long" NO_BASELINE) endif() # Test failure without a reference, please do not create a TestNoRef.png file diff --git a/library/public/image.h b/library/public/image.h index 1165c5a504..ec339cff39 100644 --- a/library/public/image.h +++ b/library/public/image.h @@ -161,7 +161,7 @@ class F3D_EXPORT image * TIF: Supports channel type BYTE, SHORT and FLOAT with channel count of 1 to 4 * BMP: Supports channel type BYTE with channel count of 1 to 4 * Throw an `image::write_exception` if the format is incompatible with with image channel type or - * channel count + * channel count or if the image cannot be written for any other reason. */ const image& save( const std::filesystem::path& filePath, SaveFormat format = SaveFormat::PNG) const;