From 24069150038bde69f686b973cead60bf950f5db0 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 13 Jun 2019 06:49:17 +0300
Subject: [PATCH] Fixes #79 infinite loop in vision node

---
 applications/vision/src/main.cpp              | 20 +++++++++++--------
 .../renderers/cpp/include/ftl/display.hpp     |  2 ++
 components/renderers/cpp/src/display.cpp      |  4 ++++
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp
index 620ebd738..0119a659a 100644
--- a/applications/vision/src/main.cpp
+++ b/applications/vision/src/main.cpp
@@ -95,16 +95,20 @@ static void run(ftl::Configurable *root) {
 	
 	Streamer *stream = ftl::create<Streamer>(root, "stream", net);
 	stream->add(source);
-	stream->run();
-
+	
 	net->start();
-	LOG(INFO) << "Running...";
 
-	while (ftl::running && display->active()) {
-		cv::Mat rgb, depth;
-		source->getFrames(rgb, depth);
-		if (!rgb.empty()) display->render(rgb, depth, source->parameters());
-		display->wait(10);
+	LOG(INFO) << "Running...";
+	if (display->hasDisplays()) {
+		stream->run();
+		while (ftl::running && display->active()) {
+			cv::Mat rgb, depth;
+			source->getFrames(rgb, depth);
+			if (!rgb.empty()) display->render(rgb, depth, source->parameters());
+			display->wait(10);
+		}
+	} else {
+		stream->run(true);
 	}
 
 	LOG(INFO) << "Stopping...";
diff --git a/components/renderers/cpp/include/ftl/display.hpp b/components/renderers/cpp/include/ftl/display.hpp
index 2e56c459b..05ae0bf11 100644
--- a/components/renderers/cpp/include/ftl/display.hpp
+++ b/components/renderers/cpp/include/ftl/display.hpp
@@ -43,6 +43,8 @@ class Display : public ftl::Configurable {
 	bool render(const cv::Mat &img, style_t s=STYLE_NORMAL);
 
 	bool active() const;
+
+	bool hasDisplays();
 	
 	void wait(int ms);
 
diff --git a/components/renderers/cpp/src/display.cpp b/components/renderers/cpp/src/display.cpp
index c255a8bcc..0f838df75 100644
--- a/components/renderers/cpp/src/display.cpp
+++ b/components/renderers/cpp/src/display.cpp
@@ -243,6 +243,10 @@ bool Display::render(const cv::Mat &img, style_t s) {
 	return true;
 }
 
+bool Display::hasDisplays() {
+	return value("depth", false) || value("left", false) || value("right", false) || value("points", false);
+}
+
 void Display::wait(int ms) {
 	if (value("points", false)) {
 		#if defined HAVE_PCL
-- 
GitLab