From b86df19f300e364dd2d10620241b61cf0f53ff54 Mon Sep 17 00:00:00 2001
From: joanvallve <jvallve@iri.upc.edu>
Date: Mon, 14 Dec 2020 13:23:53 +0100
Subject: [PATCH] bugs fixed regarding SensorBase::last_capture_

---
 src/capture/capture_base.cpp |  6 +++---
 src/sensor/sensor_base.cpp   | 12 ++++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/capture/capture_base.cpp b/src/capture/capture_base.cpp
index cc108e3a1..d06149ba3 100644
--- a/src/capture/capture_base.cpp
+++ b/src/capture/capture_base.cpp
@@ -234,9 +234,9 @@ void CaptureBase::setProblem(ProblemPtr _problem)
 
     // update SensorBase::last_capture_
     if (getSensor() and
-        getSensor()->getLastCapture() and
-        getSensor()->getLastCapture()->getTimeStamp() < time_stamp_)
-        getSensor()->setLastCapture(shared_from_this());
+        (not getSensor()->getLastCapture() or
+         getSensor()->getLastCapture()->getTimeStamp() < time_stamp_))
+         getSensor()->setLastCapture(shared_from_this());
 
     for (auto ft : feature_list_)
         ft->setProblem(_problem);
diff --git a/src/sensor/sensor_base.cpp b/src/sensor/sensor_base.cpp
index 9e7adfd0b..0e2a89c12 100644
--- a/src/sensor/sensor_base.cpp
+++ b/src/sensor/sensor_base.cpp
@@ -555,8 +555,16 @@ CheckLog SensorBase::localCheck(bool _verbose, SensorBasePtr _sen_ptr, std::ostr
         // check last_capture_
         if (getProblem()->getTimeStamp().ok())
         {
-            inconsistency_explanation << "SensorBase::last_capture_ is not the actual last capture\n";
-            log.assertTrue((last_capture_ != findLastCaptureBefore(getProblem()->getTimeStamp())), inconsistency_explanation);
+            auto last_capture_found = findLastCaptureBefore(getProblem()->getTimeStamp());
+            inconsistency_explanation << "SensorBase::last_capture_: "
+                                      << (last_capture_ ? std::to_string(last_capture_->id()) : "-")
+                                      << " @ " << last_capture_
+                                      << " is not the actual last capture: "
+                                      << (last_capture_found ?
+                                          std::to_string(last_capture_found->id()) :
+                                          "-")
+                                      << " @ " << last_capture_found << std::endl;
+            log.assertTrue(last_capture_ == last_capture_found, inconsistency_explanation);
         }
         return log;
 }
-- 
GitLab