From 0056f469931cf8b7879a5e350415bc9c3db2d30c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu>
Date: Mon, 17 Jun 2019 10:14:19 +0200
Subject: [PATCH] implemented exception of unlink a capture in case of non-KF

---
 src/capture/capture_base.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp
index db12b5847..5f0ce6880 100644
--- a/src/capture/capture_base.cpp
+++ b/src/capture/capture_base.cpp
@@ -291,7 +291,11 @@ void CaptureBase::setCalibration(const VectorXs& _calib)
 
 void CaptureBase::link(FrameBasePtr _frm_ptr)
 {
-    assert(this->getFrame() == nullptr && "linking an already linked capture");
+    assert((this->getFrame() == nullptr || !this->getFrame()->isKey()) && "linking a capture already linked to a KF");
+
+    // unlink from previous non-key frame
+    if (this->getFrame())
+        this->getFrame()->removeCapture(shared_from_this());
 
     if(_frm_ptr)
     {
-- 
GitLab