From 7775ec9a10d3076b1c389a6407a33b442c1a8a3d Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 27 Jul 2020 16:00:07 +0300
Subject: [PATCH] Reduce operators exceptions

---
 components/operators/src/fusion/mvmls.cpp | 15 +++++++++++++--
 components/operators/src/normals.cpp      |  6 ++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/components/operators/src/fusion/mvmls.cpp b/components/operators/src/fusion/mvmls.cpp
index a444d8d1a..c16b3ab43 100644
--- a/components/operators/src/fusion/mvmls.cpp
+++ b/components/operators/src/fusion/mvmls.cpp
@@ -47,8 +47,19 @@ bool MultiViewMLS::apply(ftl::rgbd::FrameSet &in, ftl::rgbd::FrameSet &out, cuda
 	bool show_consistency = config()->value("show_consistency", false);
 	bool show_adjustment = config()->value("show_adjustment", false);
 
-    if (in.frames.size() < 1) return false;
-    auto size = in.firstFrame().get<GpuMat>(Channel::Depth).size();
+    if (in.frames.size() < 1 || in.count == 0) return false;
+	cv::Size size(0,0);
+	for (auto &f : in.frames) {
+		if (f.hasChannel(Channel::Depth)) {
+			size = f.get<GpuMat>(Channel::Depth).size();
+			break;
+		}
+	}
+    
+	if (size.width == 0) {
+		in.firstFrame().message(ftl::data::Message::Warning_MISSING_CHANNEL, "Missing Depth Channel in MVMLS operator");
+		return false;
+	}
 
     // Make sure we have enough buffers
     while (normals_horiz_.size() < in.frames.size()) {
diff --git a/components/operators/src/normals.cpp b/components/operators/src/normals.cpp
index 0e89ef3ed..09618fa48 100644
--- a/components/operators/src/normals.cpp
+++ b/components/operators/src/normals.cpp
@@ -19,7 +19,8 @@ Normals::~Normals() {
 bool Normals::apply(ftl::rgbd::Frame &in, ftl::rgbd::Frame &out, cudaStream_t stream) {
 	if (!in.hasChannel(Channel::Depth)) {
 		out.message(ftl::data::Message::Warning_MISSING_CHANNEL, "Missing Depth Channel in Normals operator");
-		throw FTL_Error("Missing depth channel in Normals operator");
+		//throw FTL_Error("Missing depth channel in Normals operator");
+		return false;
 	}
 
 	if (out.hasChannel(Channel::Normals)) {
@@ -49,7 +50,8 @@ NormalDot::~NormalDot() {
 bool NormalDot::apply(ftl::rgbd::Frame &in, ftl::rgbd::Frame &out, cudaStream_t stream) {
 	if (!in.hasChannel(Channel::Depth)) {
 		out.message(ftl::data::Message::Warning_MISSING_CHANNEL, "Missing Depth Channel in Normals operator");
-		throw FTL_Error("Missing depth channel in Normals operator");
+		//throw FTL_Error("Missing depth channel in Normals operator");
+		return false;
 	}
 
 	if (out.hasChannel(Channel::Normals)) {
-- 
GitLab