diff --git a/include/openspace/navigation/navigationhandler.h b/include/openspace/navigation/navigationhandler.h index 4981274e08..ea2fdfcb44 100644 --- a/include/openspace/navigation/navigationhandler.h +++ b/include/openspace/navigation/navigationhandler.h @@ -140,7 +140,7 @@ public: NavigationState navigationState() const; NavigationState navigationState(const SceneGraphNode& referenceFrame) const; - void saveNavigationState(const std::string& filepath, + void saveNavigationState(const std::filesystem::path& filepath, const std::string& referenceFrameIdentifier); void loadNavigationState(const std::string& filepath); diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index e91f761e54..a20d6248e7 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -442,9 +442,11 @@ NavigationState NavigationHandler::navigationState( ); } -void NavigationHandler::saveNavigationState(const std::string& filepath, +void NavigationHandler::saveNavigationState(const std::filesystem::path& filepath, const std::string& referenceFrameIdentifier) { + ghoul_precondition(!filepath.empty(), "File path must not be empty"); + NavigationState state; if (!referenceFrameIdentifier.empty()) { const SceneGraphNode* referenceFrame = sceneGraphNode(referenceFrameIdentifier); @@ -461,14 +463,18 @@ void NavigationHandler::saveNavigationState(const std::string& filepath, state = navigationState(); } - if (!filepath.empty()) { - std::filesystem::path absolutePath = absPath(filepath); - LINFO(fmt::format("Saving camera position: {}", absolutePath)); + std::filesystem::path absolutePath = absPath(filepath); + LINFO(fmt::format("Saving camera position: {}", absolutePath)); - std::ofstream ofs(absolutePath); - ofs << "return " << ghoul::formatLua(state.dictionary()); - ofs.close(); + std::ofstream ofs(absolutePath); + + if (!ofs.good()) { + throw ghoul::RuntimeError(fmt::format( + "Error saving navigation state to {}", filepath + )); } + + ofs << "return " << ghoul::formatLua(state.dictionary()); } void NavigationHandler::loadNavigationState(const std::string& filepath) {