From c665c0e6c635c2c446fef3c39b59dc291be6a9d1 Mon Sep 17 00:00:00 2001 From: vhinger182 Date: Fri, 27 Feb 2026 12:17:17 +0100 Subject: [PATCH] Fix #281 std::bad_optional_access in RawMasterFile::roi() (#282) Fixes #281 --- src/RawMasterFile.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/RawMasterFile.cpp b/src/RawMasterFile.cpp index 919b2d9..46843dc 100644 --- a/src/RawMasterFile.cpp +++ b/src/RawMasterFile.cpp @@ -194,6 +194,15 @@ ScanParameters RawMasterFile::scan_parameters() const { } std::optional RawMasterFile::roi() const { + if (!m_rois) { + return std::nullopt; + } + + if (m_rois->empty()) { + throw std::runtime_error(LOCATION + + "Zero ROIs in metadata."); + } + if (m_rois.value().size() > 1) { throw std::runtime_error(LOCATION + "Multiple ROIs present, use rois() method.");