Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F3D: Improve exception handling of image::save usage #1866

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/public/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading