史诗级PCL和Eigen联合BUG

环境

系统:Ubuntu 18.04
PCL:1.8.1(系统默认)
Eigen:3.4.3(系统默认)


BUG

Thread 1 "fastlio_sam_map" received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x2c890) at malloc.c:3113
3113	malloc.c: 没有那个文件或目录.
(gdb) where
#0  __GI___libc_free (mem=0x2c890) at malloc.c:3113
#1  0x00005555555d7fdb in Eigen::internal::handmade_aligned_free (
    ptr=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:98
#2  Eigen::internal::aligned_free (ptr=<optimized out>)
    at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:179
#3  Eigen::aligned_allocator<pcl::PointXYZINormal>::deallocate (
    this=0x7fffd0016258, p=<optimized out>)
    at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:747
#4  std::allocator_traits<Eigen::aligned_allocator<pcl::PointXYZINormal> >::deallocate (__a=..., __n=<optimized out>, __p=<optimized out>)
    at /usr/include/c++/7/bits/alloc_traits.h:328
#5  std::_Vector_base<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::_M_deallocate (this=0x7fffd0016258, __n=<optimized out>, 
    __p=<optimized out>) at /usr/include/c++/7/bits/stl_vector.h:180
#6  std::_Vector_base<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::~_Vector_base (this=0x7fffd0016258, __in_chrg=<optimized out>)
    at /usr/include/c++/7/bits/stl_vector.h:162
#7  std::vector<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::~vector (this=0x7fffd0016258, __in_chrg=<optimized out>)
    at /usr/include/c++/7/bits/stl_vector.h:435
#8  pcl::PointCloud<pcl::PointXYZINormal>::~PointCloud (this=0x7fffd0016220, 
    __in_chrg=<optimized out>) at /usr/include/pcl-1.8/pcl/point_cloud.h:240
#9  pcl::PointCloud<pcl::PointXYZINormal>::~PointCloud (this=0x7fffd0016220, 

错误原因

这个bug,是在我运行SLAM算法,例如fast_lio_sam时遇到的。使用GDB调试后出现上面的报错,大致原因是Eigen在做PCL的析构的时候失败了,经过大量查阅资料发现,这是PCL和Eigen的一个版本共存的BUG,解决方法可以尝试更换PCL和Eigen版本,但是我担心破坏环境,因此采用另一种办法。


错误位置

sor的类型为你代码pcl::PointXYZI、pcl::PointXYZ等等等任意类型,只要一进入到滤波函数就会段错误,因此解决死路就是通过替换sor的类型为pcl::PointCloud2格式,进行滤波,滤波后再将点重新填入到pcl::PointXYZI格式的sor里面即可。

sor.setInputcloud(*surfCloud);
sor.filter(*srufCloud);

代码对比

修改前:

pcl::PointCloud<PointType>::Ptr cloud_temp(new pcl::PointCloud<PointType>());
downSizeFilterICP.setInputCloud(nearKeyframes);
downSizeFilterICP.filter(*cloud_temp);

修改后:

pcl::PCLPointCloud2::Ptr cloud2(new pcl::PCLPointCloud2());
pcl::PCLPointCloud2::Ptr cloud_filtered2(new pcl::PCLPointCloud2());
pcl::PointCloud<PointType>::Ptr  cloud_temp (new pcl::PointCloud<PointType>);
pcl::toPCLPointCloud2(*nearKeyframes, *cloud2);
pcl::VoxelGrid<PointType> downSizeFilter2;
pcl::VoxelGrid<pcl::PCLPointCloud2> sor2;
sor2.setInputCloud(cloud2);
sor2.setLeafSize(mappingSurfLeafSize, mappingSurfLeafSize, mappingSurfLeafSize);
sor2.filter(*cloud_filtered2);
pcl::fromPCLPointCloud2(*cloud_filtered2, *cloud_temp);
downSizeFilterICP.setInputCloud(cloud_temp);

参考链接:
链接1、链接2、链接3、链接4、链接5、链接6

你可能感兴趣的:(bug)