From 658a6bc910aa960d9a7f857fd906dccef51d2ed7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Sol=C3=A0?= <jsola@iri.upc.edu>
Date: Sun, 17 Sep 2023 13:40:41 +0200
Subject: [PATCH] Fix obscure segfault in one test

---
 test/gtest_feature_imu.cpp | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/test/gtest_feature_imu.cpp b/test/gtest_feature_imu.cpp
index 2a1a09be3..e6f70029b 100644
--- a/test/gtest_feature_imu.cpp
+++ b/test/gtest_feature_imu.cpp
@@ -81,15 +81,13 @@ class FeatureImu_test : public testing::Test
         origin_frame = problem->setPriorFactor(x0, s0, t);
         processor_motion_ptr_->setOrigin(origin_frame);
 
-    // Emplace one capture to store the Imu data arriving from (sensor / callback / file / etc.)
+    // Create one capture to store the Imu data arriving from (sensor / callback / file / etc.)
     // give the capture a big covariance, otherwise it will be so small that it won't pass following assertions
-        imu_ptr = std::static_pointer_cast<CaptureImu>(
-                CaptureBase::emplace<CaptureImu>(origin_frame,
-                                                 t,
-                                                 sensor_ptr,
-                                                 data_,
-                                                 Eigen::Matrix6d::Identity(),
-                                                 Eigen::Vector6d::Zero().eval()) );
+    imu_ptr = std::make_shared<CaptureImu>( t,
+                                            sensor_ptr,
+                                            data_,
+                                            Eigen::Matrix6d::Identity(),
+                                            Eigen::Vector6d::Zero().eval());
 
     //process data
         data_ << 2, 0, 9.8, 0, 0, 0;
@@ -102,22 +100,21 @@ class FeatureImu_test : public testing::Test
     // process data in capture
         sensor_ptr->process(imu_ptr);
 
-    //emplace Frame
-        ts          = problem->getTimeStamp();
-        state_vec   = problem->getState().vector(problem->getFrameStructure());
-        last_frame  = problem->emplaceFrame(ts, state_vec);
 
     //emplace a feature
         delta_preint            = processor_motion_ptr_->getMotion().delta_integr_;
         delta_preint_cov        = processor_motion_ptr_->getMotion().delta_integr_cov_ + MatrixXd::Identity(9,9)*1e-08;
         VectorXd calib_preint   = processor_motion_ptr_->getLast()->getCalibrationPreint();
         dD_db_jacobians         = processor_motion_ptr_->getMotion().jacobian_calib_;
-        feat_imu                = FeatureBase::emplace<FeatureImu>(imu_ptr,
+        feat_imu                = FeatureBase::emplace<FeatureImu>(processor_motion_ptr_->getOrigin(),
                                                                    delta_preint,
                                                                    delta_preint_cov,
                                                                    calib_preint,
                                                                    dD_db_jacobians,
-                                                                   imu_ptr) ;
+                                                                   processor_motion_ptr_->getOrigin()) ;
+
+        problem->print(4,1,1,1);        
+
     }
 
     void TearDown() override
@@ -155,7 +152,7 @@ TEST_F(FeatureImu_test, check_frame)
     left_vptr = left_frame->getV();
 
     ASSERT_MATRIX_APPROX(origin_pptr->getState(), left_pptr->getState(), wolf::Constants::EPS_SMALL);
-    Eigen::Map<const Eigen::Quaterniond> origin_Quat(origin_optr->getState().data()), left_Quat(left_optr->getState().data());
+    Eigen::Quaterniond origin_Quat(origin_optr->getState().data()), left_Quat(left_optr->getState().data());
     ASSERT_QUATERNION_APPROX(origin_Quat, left_Quat, wolf::Constants::EPS_SMALL);
     ASSERT_MATRIX_APPROX(origin_vptr->getState(), left_vptr->getState(), wolf::Constants::EPS_SMALL);
 
-- 
GitLab