史诗级PCL和Eigen联合BUG

环境

系统:Ubuntu 18.04

PCL:1.8.1(系统默认)

Eigen:3.4.3(系统默认)


BUG

cpp 复制代码
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里面即可。

cpp 复制代码
sor.setInputcloud(*surfCloud);
sor.filter(*srufCloud);

代码对比

修改前:

cpp 复制代码
pcl::PointCloud<PointType>::Ptr cloud_temp(new pcl::PointCloud<PointType>());
downSizeFilterICP.setInputCloud(nearKeyframes);
downSizeFilterICP.filter(*cloud_temp);

修改后:

cpp 复制代码
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

相关推荐
hello_2502 小时前
bug排查思路大纲
bug
秃头小饼干2 小时前
关于Bug排查日记的技术文章大纲
bug
烧冻鸡翅QAQ2 小时前
测试中的Bug
bug·测试
云和数据.ChenGuang1 天前
java常见SSL bug解决方案
java·bug·ssl
cat_with_cat2 天前
测试:BUG篇
bug·测试
黑客飓风2 天前
Bug排查日记的技术
bug
Wiktok2 天前
[Wit]CnOCR模型训练全流程简化记录(包括排除BUG)
python·深度学习·bug
玄尺_0072 天前
bug:uniCloud报Business Failed, 参数有误retry invoke error
数据库·bug
程序猿阿伟2 天前
《云原生边缘与AI训练场景:2类高频隐蔽Bug的深度排查与架构修复》
人工智能·云原生·bug
夕阳UPdz2 天前
深入探索 Unity 错误排查过程:从“滚动条问题”到“鼠标悬浮异常”
bug