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 bd9e356
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 @@ -451,6 +451,7 @@ f3d_test(NAME TestCameraIndexNegative DATA Cameras.gltf ARGS --camera-index=-1 R
# Require improved importer support https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11303
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240910)
f3d_test(NAME TestInvalidFileFileName DATA invalid.vtp ARGS --filename NO_DATA_FORCE_RENDER UI)
f3d_test(NAME TestMultiFileInvalid DATA cow.vtp invalid.vtp dragon.vtu ARGS --multi-file-mode=all NO_DATA_FORCE_RENDER UI)
f3d_test(NAME TestMultiFileInvalidFilesFileName DATA mb/mb_3_0.vtt invalid.vtp ARGS --multi-file-mode=all --filename NO_DATA_FORCE_RENDER UI)
f3d_test(NAME TestMultiFileCameraIndex DATA Cameras.gltf CameraAnimated.glb ARGS --multi-file-mode=all --camera-index=2 --opacity=0.5 --translucency-support)
endif()
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 bd9e356

Please sign in to comment.