My definition of the struct are
#include <vector>
#include <Eigen/Dense>
#include "lanenet_cfg.h"
#include "mytimer.h"
#include <opencv2/opencv.hpp>
#define N_MAX_CAMERA_LANE (4U)
#define N_MAX_TIMING (50U)
namespace lanenet{
enum class LaneColorType {
WHITE_DASHED = 0,
WHITE_SOLID,
YELLOW_DASHED,
YELLOW_SOLID
};
typedef struct {
double C0;
double C1;
double C2;
double C3;
}lanePoly_t;
typedef enum {
THIRD_LEFT = -3,
ADJACENT_LEFT = -2,
EGO_LEFT = -1,
EGO_CENTER = 0,
EGO_RIGHT = 1,
ADJACENT_RIGHT = 2,
THIRD_RIGHT = 3,
OTHER = 6,
UNKNOWN = 7
}LanePos_t;
typedef enum {
LANE_REAL = 0,
LANE_VIRTUAL
} laneUsed_t;
typedef struct {
bool isValid;
lanePoly_t lanePoly[4];
int num_poly_used;
float prob;
LanePos_t lanePos;
laneUsed_t laneUsedType;
int laneSrc;
int quality;
} lane_t;
class timeMea {
public:
int i;
public:
MyTimer mt_detection[N_MAX_TIMING];
MyTimer mt_preprocess[N_MAX_TIMING];
};
typedef struct {
lane_t lane[N_MAX_CAMERA_LANE];
int iCurrLane;
double timestamp;
std::vector<std::vector<Eigen::Matrix<float, 2, 1>>> coords_fit;
std::vector<std::vector<Eigen::Matrix<float, 2, 1>>> coords_avg;
timeMea time_mea;
std::string imageFullPath;
cv::Mat img_source;
bool is_video;
} laneList_t;
}// endof lanenet namespace
lanenet::laneList_t glaneList;
int main(){
memset(&glaneList,0, sizeof(laneList_t));
glaneList.is_video = false;
glaneList.imageFullPath ="";
}
My environments are Ubuntu 20.04 +vscode,use C++14, and compiler is GCC9.4.0_X86_64-linux-gnu, segmentation fault happened on line
laneList.imageFullPath ="";
after memset() function. in gdb, it states
Reading symbols from laneDet...
[New LWP 7742]
[New LWP 7746]
[New LWP 7749]
[New LWP 7745]
[New LWP 7750]
[New LWP 7743]
[New LWP 7744]
[New LWP 7753]
[New LWP 7752]
[New LWP 7748]
[New LWP 7747]
[New LWP 7757]
[New LWP 7751]
[New LWP 7756]
[New LWP 7758]
[New LWP 7755]
[New LWP 7754]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/home/xxx/laneNetCPP_ubuntu_trt/build/laneDe'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:314
314 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.
[Current thread is 1 (Thread 0x7fec1ba28000 (LWP 7742))]
(gdb)
gdb debug information prompts alignment problem, and if I remove the memset() statement in main()
memset(&glaneList,0, sizeof(laneList_t));
there is no segmentation fault, so I guess The promble seems caused by alignment related and memset() related
P.S., for a long time, this code runs well, recently when I rebuild with C++11, it prompts segmentation fault, sometime it runs successfully.
Any help will be appreciated.