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

context: Add exception handling #2064

Merged
merged 7 commits into from
Mar 16, 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
51 changes: 37 additions & 14 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -936,29 +936,52 @@
bool offscreen = !this->Internals->AppOptions.Reference.empty() ||
!this->Internals->AppOptions.Output.empty() || this->Internals->AppOptions.BindingsList;

if (this->Internals->AppOptions.RenderingBackend == "egl")
try
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createEGL());
if (this->Internals->AppOptions.RenderingBackend == "egl")
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createEGL());
}
else if (this->Internals->AppOptions.RenderingBackend == "osmesa")
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createOSMesa());
}
else if (this->Internals->AppOptions.RenderingBackend == "glx")
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createGLX(offscreen));
}
else if (this->Internals->AppOptions.RenderingBackend == "wgl")
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createWGL(offscreen));
}
else
{
if (this->Internals->AppOptions.RenderingBackend != "auto")
{
f3d::log::warn("--rendering-backend value is invalid, falling back to \"auto\"");
}
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::create(offscreen));
}
}
else if (this->Internals->AppOptions.RenderingBackend == "osmesa")
catch (const f3d::context::loading_exception& ex)
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createOSMesa());
f3d::log::error("Could not load graphic library: ", ex.what());
return EXIT_FAILURE;
}
else if (this->Internals->AppOptions.RenderingBackend == "glx")
catch (const f3d::context::symbol_exception& ex)
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createGLX(offscreen));
f3d::log::error("Could not find needed symbol in graphic library: ", ex.what());
return EXIT_FAILURE;
}
else if (this->Internals->AppOptions.RenderingBackend == "wgl")
catch (const f3d::engine::no_window_exception& ex)
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createWGL(offscreen));
f3d::log::error("Could not create the window: ", ex.what());
return EXIT_FAILURE;
}
else
catch (const f3d::engine::cache_exception& ex)
{
if (this->Internals->AppOptions.RenderingBackend != "auto")
{
f3d::log::warn("--rendering-backend value is invalid, falling back to \"auto\"");
}
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::create(offscreen));
f3d::log::error("Could not use default cache directory: ", ex.what());
return EXIT_FAILURE;

Check warning on line 984 in application/F3DStarter.cxx

View check run for this annotation

Codecov / codecov/patch

application/F3DStarter.cxx#L983-L984

Added lines #L983 - L984 were not covered by tests
}

this->ResetWindowName();
Expand Down
2 changes: 2 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES PASS_REGULAR_EXP
set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES ENVIRONMENT "CTEST_F3D_NO_DATA_FORCE_RENDER=1")

if(NOT WIN32)
f3d_test(NAME TestInvalidCache ENV "HOME=" REGEXP "Could not use default cache directory" NO_BASELINE)

add_test(NAME f3d::TestHOMEOutput COMMAND $<TARGET_FILE:f3d> ${F3D_SOURCE_DIR}/testing/data/suzanne.stl --output=~/Testing/Temporary/TestHOMEOutput.png --resolution=300,300 --no-config)
set_tests_properties(f3d::TestHOMEOutput PROPERTIES ENVIRONMENT "HOME=${CMAKE_BINARY_DIR}")
set_tests_properties(f3d::TestHOMEOutput PROPERTIES FIXTURES_SETUP f3d::TestHOMEOutput_FIXTURE)
Expand Down
1 change: 1 addition & 0 deletions library/src/engine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ engine::engine(
#endif
if (cachePath.empty())
{
delete Internals;
throw engine::cache_exception(
"Could not setup cache, please set the appropriate environment variable");
}
Expand Down