From 34e0918eddd714ccb7f238b5358f34eca825e851 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu>
Date: Wed, 10 Jul 2019 14:23:15 +0200
Subject: [PATCH] small changes

---
 src/capture/capture_base.cpp |  1 +
 src/factor/factor_base.cpp   | 13 +++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp
index 5d2fb35e0..1dde62302 100644
--- a/src/capture/capture_base.cpp
+++ b/src/capture/capture_base.cpp
@@ -315,6 +315,7 @@ void CaptureBase::move(FrameBasePtr _frm_ptr)
 
 void CaptureBase::link(FrameBasePtr _frm_ptr)
 {
+    assert(!is_removing_ && "linking a removed capture");
     assert(this->getFrame() == nullptr && "linking a capture already linked");
 
     if(_frm_ptr)
diff --git a/src/factor/factor_base.cpp b/src/factor/factor_base.cpp
index 59f1961d5..ba66157fe 100644
--- a/src/factor/factor_base.cpp
+++ b/src/factor/factor_base.cpp
@@ -49,7 +49,7 @@ void FactorBase::remove()
     if (!is_removing_)
     {
         is_removing_ = true;
-        FactorBasePtr this_c = shared_from_this(); // keep this alive while removing it
+        FactorBasePtr this_fac = shared_from_this(); // keep this alive while removing it
         FeatureBasePtr f = feature_ptr_.lock();
         if (f)
         {
@@ -59,13 +59,13 @@ void FactorBase::remove()
         }
         // add factor to be removed from solver
         if (getProblem() != nullptr)
-            getProblem()->notifyFactor(shared_from_this(),REMOVE);
+            getProblem()->notifyFactor(this_fac,REMOVE);
 
         // remove other: {Frame, Capture, Feature, Landmark}
         FrameBasePtr frm_o = frame_other_ptr_.lock();
         if (frm_o)
         {
-            frm_o->removeConstrainedBy(shared_from_this());
+            frm_o->removeConstrainedBy(this_fac);
             if (frm_o->getConstrainedByList().empty() && frm_o->getCaptureList().empty())
                 frm_o->remove();
         }
@@ -73,7 +73,7 @@ void FactorBase::remove()
         CaptureBasePtr cap_o = capture_other_ptr_.lock();
         if (cap_o)
         {
-            cap_o->removeConstrainedBy(shared_from_this());
+            cap_o->removeConstrainedBy(this_fac);
             if (cap_o->getConstrainedByList().empty() && cap_o->getFeatureList().empty())
                 cap_o->remove();
         }
@@ -81,7 +81,7 @@ void FactorBase::remove()
         FeatureBasePtr ftr_o = feature_other_ptr_.lock();
         if (ftr_o)
         {
-            ftr_o->removeConstrainedBy(shared_from_this());
+            ftr_o->removeConstrainedBy(this_fac);
             if (ftr_o->getConstrainedByList().empty() && ftr_o->getFactorList().empty())
                 ftr_o->remove();
         }
@@ -89,7 +89,7 @@ void FactorBase::remove()
         LandmarkBasePtr lmk_o = landmark_other_ptr_.lock();
         if (lmk_o)
         {
-            lmk_o->removeConstrainedBy(shared_from_this());
+            lmk_o->removeConstrainedBy(this_fac);
             if (lmk_o->getConstrainedByList().empty())
                 lmk_o->remove();
         }
@@ -143,6 +143,7 @@ void FactorBase::setStatus(FactorStatus _status)
 
 void FactorBase::link(FeatureBasePtr _ftr_ptr)
 {
+    assert(!is_removing_ && "linking a removed factor");
     assert(this->getFeature() == nullptr && "linking an already linked factor");
 
     // not link if nullptr
-- 
GitLab