From ea1ad581c6a77acc8c94381346c308ac42e50150 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 23 Mar 2025 23:18:39 +0100 Subject: [PATCH] Improve error handling for ar playbacks --- .../AR/Provider/Playback/ArPlaybackReader.hpp | 4 +-- openVulkanoCpp/IO/Files/Pfm.hpp | 26 +++++++++++-------- openVulkanoCpp/IO/Files/Pnm.hpp | 22 +++++++++------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp b/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp index 2fd0ee6..0d7b716 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp @@ -83,8 +83,8 @@ namespace OpenVulkano::AR::Playback DepthImage ReadDepthImage() { DepthImage img; - m_archiveDepth.GetNextFileAsStream([&img](const FileDescription& desc, std::istream& stream) { img.depth.Read(stream); }); - if (!m_archiveConfidence.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.confidence.Read(stream); })) + m_archiveDepth.GetNextFileAsStream([&img](const FileDescription& desc, std::istream& stream) { img.depth.TryRead(stream); }); + if (!m_archiveConfidence.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.confidence.TryRead(stream); })) { // No confidence image available img.confidence.header.width = img.confidence.header.height = 1; img.confidence.image = std::make_unique(m_imgTotalSize); diff --git a/openVulkanoCpp/IO/Files/Pfm.hpp b/openVulkanoCpp/IO/Files/Pfm.hpp index addf58e..eb48817 100644 --- a/openVulkanoCpp/IO/Files/Pfm.hpp +++ b/openVulkanoCpp/IO/Files/Pfm.hpp @@ -12,6 +12,8 @@ #include #include +#include "../../../../cmake-build/release/_deps/ryml-src/ext/c4core/src/c4/format.hpp" + namespace OpenVulkano { //TODO handle comments @@ -118,8 +120,18 @@ namespace OpenVulkano } } } - - operator bool() const { return image; } + + void TryRead(std::istream& inStream) + { + try { Read(inStream); } + catch (const std::exception& e) + { + header.height = header.width = 0; + image = nullptr; + } + } + + operator bool() const { return static_cast(image); } static PfmImage ReadImage(std::istream& inStream) { @@ -131,15 +143,7 @@ namespace OpenVulkano static PfmImage TryReadImage(std::istream& inStream) { PfmImage image; - try - { - image.Read(inStream); - } - catch (const std::exception& e) - { - image.header.height = image.header.width = 0; - image.image = nullptr; - } + image.TryRead(inStream); return image; } }; diff --git a/openVulkanoCpp/IO/Files/Pnm.hpp b/openVulkanoCpp/IO/Files/Pnm.hpp index 904f772..35585c7 100644 --- a/openVulkanoCpp/IO/Files/Pnm.hpp +++ b/openVulkanoCpp/IO/Files/Pnm.hpp @@ -150,8 +150,18 @@ namespace OpenVulkano image = std::make_unique(size); inStream.read(image.get(), size); } + + void TryRead(std::istream& inStream) + { + try { Read(inStream); } + catch (const std::exception& e) + { + header.height = header.width = 0; + image = nullptr; + } + } - operator bool() const { return image; } + operator bool() const { return static_cast(image); } static PnmImage ReadImage(std::istream& inStream) { @@ -163,15 +173,7 @@ namespace OpenVulkano static PfmImage TryReadImage(std::istream& inStream) { PfmImage image; - try - { - image.Read(inStream); - } - catch (const std::exception& e) - { - image.header.height = image.header.width = 0; - image.image = nullptr; - } + image.TryRead(inStream); return image; } };