From 5e6476a3c24312279c53d59469a610aaa69ed35f Mon Sep 17 00:00:00 2001
From: jcasals <jcasals@iri.upc.edu>
Date: Tue, 15 Sep 2020 14:58:46 +0200
Subject: [PATCH] Change assertions for nullptr if/else checks

Change the assertions so that we can run the visualizer
on a thread and handle incomplete information cases.
---
 src/factor/factor_base.cpp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/factor/factor_base.cpp b/src/factor/factor_base.cpp
index 4e18cb47d..a0b4bc900 100644
--- a/src/factor/factor_base.cpp
+++ b/src/factor/factor_base.cpp
@@ -151,20 +151,23 @@ void FactorBase::remove(bool viral_remove_empty_parent)
 
 CaptureBasePtr FactorBase::getCapture() const
 {
-    assert(getFeature() != nullptr && "calling getCapture before linking with a feature");
-    return getFeature()->getCapture();
+    auto ftr = getFeature();
+    if (ftr != nullptr) return ftr->getCapture();
+    else return nullptr;
 }
 
 FrameBasePtr FactorBase::getFrame() const
 {
-    assert(getCapture() != nullptr && "calling getFrame before linking with a capture");
-    return getCapture()->getFrame();
+    auto cpt = getCapture();
+    if(cpt != nullptr) return cpt->getFrame();
+    else return nullptr;
 }
 
 SensorBasePtr FactorBase::getSensor() const
 {
-    assert(getCapture() != nullptr && "calling getSensor before linking with a capture");
-    return getCapture()->getSensor();
+    auto cpt = getCapture();
+    if(cpt != nullptr) return cpt->getSensor();
+    else return nullptr;
 }
 
 void FactorBase::setStatus(FactorStatus _status)
-- 
GitLab