史诗级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

相关推荐
阿奇__13 小时前
el-table有固定列时样式bug
vue.js·elementui·bug
残花月伴2 天前
天机学堂——day1(修改bug)
servlet·bug
std860212 天前
微软 Win11 经典版 Outlook 曝 BUG,加速 SSD 损耗
microsoft·bug·outlook
花花鱼2 天前
android 网络访问拦截器使用后的bug处理
bug
JH30733 天前
MyBatis多表联查返回List仅一条数据?主键冲突BUG排查与解决
bug·mybatis
约翰先森不喝酒3 天前
Android BUG 之 资源文件报红但不影响运行
bug
百花~3 天前
认识BUG~
bug
ZHE|张恒3 天前
RDP 远程桌面连接:浏览器无法获取摄像头
bug
chde2Wang4 天前
Linux中bash: ls: 未找到命令… 相似命令是: ‘lz‘
linux·运维·bug·bash
阿里巴巴淘系技术团队官网博客4 天前
让AI打出丝滑连招:编码-部署-自测-改bug
人工智能·bug