Skip to content

Commit 877959f

Browse files
context: Add exception handling (#2064)
- Add context exception handling - Add test
1 parent f59acec commit 877959f

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

application/F3DStarter.cxx

+37-14
Original file line numberDiff line numberDiff line change
@@ -945,29 +945,52 @@ int F3DStarter::Start(int argc, char** argv)
945945
bool offscreen = !this->Internals->AppOptions.Reference.empty() ||
946946
!this->Internals->AppOptions.Output.empty() || this->Internals->AppOptions.BindingsList;
947947

948-
if (this->Internals->AppOptions.RenderingBackend == "egl")
948+
try
949949
{
950-
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createEGL());
950+
if (this->Internals->AppOptions.RenderingBackend == "egl")
951+
{
952+
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createEGL());
953+
}
954+
else if (this->Internals->AppOptions.RenderingBackend == "osmesa")
955+
{
956+
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createOSMesa());
957+
}
958+
else if (this->Internals->AppOptions.RenderingBackend == "glx")
959+
{
960+
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createGLX(offscreen));
961+
}
962+
else if (this->Internals->AppOptions.RenderingBackend == "wgl")
963+
{
964+
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createWGL(offscreen));
965+
}
966+
else
967+
{
968+
if (this->Internals->AppOptions.RenderingBackend != "auto")
969+
{
970+
f3d::log::warn("--rendering-backend value is invalid, falling back to \"auto\"");
971+
}
972+
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::create(offscreen));
973+
}
951974
}
952-
else if (this->Internals->AppOptions.RenderingBackend == "osmesa")
975+
catch (const f3d::context::loading_exception& ex)
953976
{
954-
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createOSMesa());
977+
f3d::log::error("Could not load graphic library: ", ex.what());
978+
return EXIT_FAILURE;
955979
}
956-
else if (this->Internals->AppOptions.RenderingBackend == "glx")
980+
catch (const f3d::context::symbol_exception& ex)
957981
{
958-
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createGLX(offscreen));
982+
f3d::log::error("Could not find needed symbol in graphic library: ", ex.what());
983+
return EXIT_FAILURE;
959984
}
960-
else if (this->Internals->AppOptions.RenderingBackend == "wgl")
985+
catch (const f3d::engine::no_window_exception& ex)
961986
{
962-
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::createWGL(offscreen));
987+
f3d::log::error("Could not create the window: ", ex.what());
988+
return EXIT_FAILURE;
963989
}
964-
else
990+
catch (const f3d::engine::cache_exception& ex)
965991
{
966-
if (this->Internals->AppOptions.RenderingBackend != "auto")
967-
{
968-
f3d::log::warn("--rendering-backend value is invalid, falling back to \"auto\"");
969-
}
970-
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::engine::create(offscreen));
992+
f3d::log::error("Could not use default cache directory: ", ex.what());
993+
return EXIT_FAILURE;
971994
}
972995

973996
this->ResetWindowName();

application/testing/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,8 @@ set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES PASS_REGULAR_EXP
12131213
set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES ENVIRONMENT "CTEST_F3D_NO_DATA_FORCE_RENDER=1")
12141214

12151215
if(NOT WIN32)
1216+
f3d_test(NAME TestInvalidCache ENV "HOME=" REGEXP "Could not use default cache directory" NO_BASELINE)
1217+
12161218
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)
12171219
set_tests_properties(f3d::TestHOMEOutput PROPERTIES ENVIRONMENT "HOME=${CMAKE_BINARY_DIR}")
12181220
set_tests_properties(f3d::TestHOMEOutput PROPERTIES FIXTURES_SETUP f3d::TestHOMEOutput_FIXTURE)

library/src/engine.cxx

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ engine::engine(
8585
#endif
8686
if (cachePath.empty())
8787
{
88+
delete Internals;
8889
throw engine::cache_exception(
8990
"Could not setup cache, please set the appropriate environment variable");
9091
}

0 commit comments

Comments
 (0)