Skip to content

Commit

Permalink
scene: Improve behavior when failing to load a file
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Jan 5, 2025
1 parent dbf7aa6 commit 36a9550
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ f3d_test(NAME TestMultiFileColoring DATA mb/recursive ARGS --multi-file-mode=all
f3d_test(NAME TestMultiFileVolume DATA multi ARGS --multi-file-mode=all -vsb --coloring-array=Scalars_)
f3d_test(NAME TestMultiFileColoringTexture DATA mb/recursive/mb_1_0.vtp mb/recursive/mb_2_0.vtp world.obj ARGS --multi-file-mode=all -sb --coloring-array=Normals --coloring-component=1)
f3d_test(NAME TestMultiFilePositionals DATA mb/recursive/mb_0_0.vtu mb/recursive/mb_1_0.vtp ARGS --multi-file-mode=all -s --coloring-array=Polynomial -b)
f3d_test(NAME TestMultiFileInvalid DATA cow.vtp invalid.vtp dragon.vtu ARGS --multi-file-mode=all NO_DATA_FORCE_RENDER UI)
f3d_test(NAME TestMultiFileNonCoherentComponentNames DATA bluntfin.vts bluntfin_t.vtu ARGS --multi-file-mode=all --scalar-coloring --coloring-array=Momentum --coloring-component=2 --coloring-scalar-bar)
f3d_test(NAME TestMultiInputArg ARGS --input ${F3D_SOURCE_DIR}/testing/data/mb/recursive/mb_0_0.vtu ${F3D_SOURCE_DIR}/testing/data/mb/recursive/mb_1_0.vtp --multi-file-mode=all -s --coloring-array=Polynomial -b)
f3d_test(NAME TestMultiInputMultiArgs ARGS --input ${F3D_SOURCE_DIR}/testing/data/mb/recursive/mb_0_0.vtu --input ${F3D_SOURCE_DIR}/testing/data/mb/recursive/mb_1_0.vtp --multi-file-mode=all -s --coloring-array=Polynomial -b)
Expand Down
2 changes: 2 additions & 0 deletions library/public/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class F3D_EXPORT scene
/**
* Add and load provided files into the scene
* Already added file will NOT be reloaded
* If it fails to loads a file, it clear the scene and
* throw a load_failure_exception.
*/
virtual scene& add(const std::filesystem::path& filePath) = 0;
virtual scene& add(const std::vector<std::filesystem::path>& filePath) = 0;
Expand Down
4 changes: 3 additions & 1 deletion library/src/scene_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ class scene_impl::internals
&callbackData, this->MetaImporter, this->Interactor);
}

// Update the meta importer, the will only update importers that have not been update before
// Update the meta importer, the will only update importers that have not been updated before
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240707)
if (!this->MetaImporter->Update())
{
this->MetaImporter->Clear();
this->Window.Initialize();
throw scene::load_failure_exception("failed to load scene");
}
#else
Expand Down
4 changes: 4 additions & 0 deletions library/testing/TestSDKSceneInvalid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ int TestSDKSceneInvalid(int argc, char* argv[])
f3d::engine eng = f3d::engine::createNone();
f3d::scene& sce = eng.getScene();

std::string validFilename = "cow.vtp";
std::string invalidDefaultSceneFilename = "invalid.vtp";
std::string invalidFullSceneFilename = "duck_invalid.gltf";
std::string validePath = std::string(argv[1]) + "data/" + validFilename;
std::string invalidDefaultScene = std::string(argv[1]) + "data/" + invalidDefaultSceneFilename;
std::string invalidFullScene = std::string(argv[1]) + "data/" + invalidFullSceneFilename;

test.expect<f3d::scene::load_failure_exception>(
"add with invalid default scene file", [&]() { sce.add(invalidDefaultScene); });
test.expect<f3d::scene::load_failure_exception>(
"add with invalid full scene file", [&]() { sce.add(invalidFullScene); });
test.expect<f3d::scene::load_failure_exception>(
"add with invalid multiple files", [&]() { sce.add({validFilename, invalidFullScene, invalidDefaultScene}); });

return test.result();
}
3 changes: 3 additions & 0 deletions testing/baselines/TestMultiFileInvalid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 36a9550

Please sign in to comment.