From 52f297678688a718e71ef20e5f261b4cab2cd012 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu>
Date: Mon, 27 Jun 2022 00:25:44 +0200
Subject: [PATCH] Advance this just before pointers

---
 src/processor/processor_tracker.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/processor/processor_tracker.cpp b/src/processor/processor_tracker.cpp
index b0e08b4b5..623066614 100644
--- a/src/processor/processor_tracker.cpp
+++ b/src/processor/processor_tracker.cpp
@@ -90,8 +90,9 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
             // TrackerLandmark: If we have been given a map, all landmarks in the map are known. Process them.
             processKnown();
 
-            // Update pointers
+            // Reset this
             resetDerived();
+            // Update pointers
             origin_ptr_     = incoming_ptr_;
             last_ptr_       = incoming_ptr_;
             incoming_ptr_   = nullptr;
@@ -119,8 +120,9 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
             // Issue KF callback with new KF
             getProblem()->keyFrameCallback(keyframe, shared_from_this());
 
-            // Update pointers
+            // Reset this
             resetDerived();
+            // Update pointers
             origin_ptr_ = incoming_ptr_;
             last_ptr_   = incoming_ptr_;
             incoming_ptr_ = nullptr;
@@ -163,8 +165,9 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
             // Establish factors
             establishFactors();
 
-            // Update pointers
+            // Reset this
             resetDerived();
+            // Update pointers
             origin_ptr_ = last_ptr_;
             last_ptr_   = incoming_ptr_;
             last_frame_ptr_ = keyframe;
@@ -199,8 +202,9 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
             // Establish factors
             establishFactors();
 
-            // Update pointers
+            // Reset this
             resetDerived();
+            // Update pointers
             origin_ptr_     = last_ptr_;
             last_ptr_       = incoming_ptr_;
             last_frame_ptr_ = frame;
@@ -237,8 +241,9 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
                                                                  getProblem()->getState(incoming_ptr_->getTimeStamp()));
                 incoming_ptr_   ->link(frame);
 
-                // Update pointers
+                // Reset this
                 resetDerived();
+                // Update pointers
                 origin_ptr_     = last_ptr_;
                 last_ptr_       = incoming_ptr_;
                 last_frame_ptr_ = frame;
@@ -249,9 +254,6 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
             {
                 // We do not create a KF
 
-                // Advance this
-                advanceDerived();
-
                 // Replace last frame for a new NON KEY frame in incoming
                 FrameBasePtr frame = std::make_shared<FrameBase>(incoming_ptr_->getTimeStamp(),
                                                                  getProblem()->getFrameStructure(),
@@ -259,6 +261,8 @@ void ProcessorTracker::processCapture(CaptureBasePtr _incoming_ptr)
                 incoming_ptr_->link(frame);
                 last_ptr_->unlink(); // unlink last (destroying the frame) instead of frame destruction that would implicitly destroy last
 
+                // Advance this
+                advanceDerived();
                 // Update pointers
                 last_ptr_       = incoming_ptr_;
                 last_frame_ptr_ = frame;
-- 
GitLab