Improve error handling for ar playbacks

This commit is contained in:
Georg Hagen
2025-03-23 23:18:39 +01:00
parent b68bdea1c6
commit ea1ad581c6
3 changed files with 29 additions and 23 deletions

View File

@@ -83,8 +83,8 @@ namespace OpenVulkano::AR::Playback
DepthImage ReadDepthImage() DepthImage ReadDepthImage()
{ {
DepthImage img; DepthImage img;
m_archiveDepth.GetNextFileAsStream([&img](const FileDescription& desc, std::istream& stream) { img.depth.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.Read(stream); })) if (!m_archiveConfidence.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.confidence.TryRead(stream); }))
{ // No confidence image available { // No confidence image available
img.confidence.header.width = img.confidence.header.height = 1; img.confidence.header.width = img.confidence.header.height = 1;
img.confidence.image = std::make_unique<char[]>(m_imgTotalSize); img.confidence.image = std::make_unique<char[]>(m_imgTotalSize);

View File

@@ -12,6 +12,8 @@
#include <iomanip> #include <iomanip>
#include <memory> #include <memory>
#include "../../../../cmake-build/release/_deps/ryml-src/ext/c4core/src/c4/format.hpp"
namespace OpenVulkano namespace OpenVulkano
{ {
//TODO handle comments //TODO handle comments
@@ -119,7 +121,17 @@ 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<bool>(image); }
static PfmImage ReadImage(std::istream& inStream) static PfmImage ReadImage(std::istream& inStream)
{ {
@@ -131,15 +143,7 @@ namespace OpenVulkano
static PfmImage TryReadImage(std::istream& inStream) static PfmImage TryReadImage(std::istream& inStream)
{ {
PfmImage image; PfmImage image;
try image.TryRead(inStream);
{
image.Read(inStream);
}
catch (const std::exception& e)
{
image.header.height = image.header.width = 0;
image.image = nullptr;
}
return image; return image;
} }
}; };

View File

@@ -151,7 +151,17 @@ namespace OpenVulkano
inStream.read(image.get(), size); inStream.read(image.get(), size);
} }
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<bool>(image); }
static PnmImage ReadImage(std::istream& inStream) static PnmImage ReadImage(std::istream& inStream)
{ {
@@ -163,15 +173,7 @@ namespace OpenVulkano
static PfmImage TryReadImage(std::istream& inStream) static PfmImage TryReadImage(std::istream& inStream)
{ {
PfmImage image; PfmImage image;
try image.TryRead(inStream);
{
image.Read(inStream);
}
catch (const std::exception& e)
{
image.header.height = image.header.width = 0;
image.image = nullptr;
}
return image; return image;
} }
}; };