In my project, there is a pointer to the object of a class, in which one of the class member is a pointer to struct. I want to access to the pointer to struct and reset its value. But when I tried calling it, even just printing its current value, the segmentation fault would be throwm off.
I found the error occured when I calling the pointer, even just calling it and printing its value.
Here is part of my code.
In A.h header file:
#ifndef IMU_TOOL_H
#define IMU_TOOL_H
#include <fstream>
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <Eigen/Dense>
......
......
#include <gtsam/navigation/ImuFactor.h>
......
......
using namespace gtsam;
using namespace std;
namespace Mobile_Sensing
{
class IMUHelper
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
IMUHelper()
{
......
......
priorVelocity_ = Vector3(0, 0, 0);
lastTimestamp_ = 0;
......
......
}
public:
Vector3 priorVelocity_;
long long lastTimestamp_;
......
......
};
class Factor_Graph_Optimization
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
public:
Factor_Graph_Optimization();
void backendInitialization(Scan* scan, SPANPose* imu);
inline void setVelocityPrior(const Vector3& priorVelocity) {
imuTool_->priorVelocity_ = priorVelocity;}
inline void setStartTimestamp(const long long& startTime) {
imuTool_->lastTimestamp_ = startTime; }
public:
IMUHelper* imuTool_;
......
......
};
}
#endif
In the A.cpp source file
#include <A.h>
namespace Mobile_Sensing
{
Factor_Graph_Optimization::Factor_Graph_Optimization()
{
imuTool_ = new IMUHelper();
imuTool_->initialization();
......
......
}
void Factor_Graph_Optimization::backend_initialization(Scan* scan, SPANPose* imu)
{
// if (NULL==imuTool_) // ERROR OCCURED HERE!!!
// std::cout << "ERROR: empty imuTool pointer!!" << std::endl;
// set velocity prior
Vector3 priorVelocity(imu->vf_, imu->vl_, imu->vu_);
// set_velocity_prior(priorVelocity); // ERROR OCCURED HERE!!!
// set start timestamp
setStarttimestamp(imu->timestamp_); // ERROR OCCURED HERE!!!
......
......
}
}
The segmentation error occured when I calling the pointer. I don't why and how to solve this problem. Please help!!!!!!!
Aucun commentaire:
Enregistrer un commentaire