【发布时间】:2015-04-15 17:34:23
【问题描述】:
最小可重现错误:
int main( int argc, char** argv)
{ //std::cout << "initial area_seg" << std::endl;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>() );
if (pcl::io::loadPCDFile<pcl::PointXYZRGB> (argv[1], *cloud) == -1){
PCL_ERROR ("Couldn't read the input file \n");
return (-1);
}
std::cout << "floor cloud" << std::endl;
pcl::PointCloud<pcl::PointXYZRGB> cloud_cut;
//custom void func that takes cloud in, and returns(by reference) cloud_cut
area_seg(-5,5,.15,5,-5,5,cloud, cloud_cut, "null");
pcl::PointCloud<pcl::PointXYZRGB>::Ptr floor_cut(&cloud_cut);//Fault HERE
return 0;
}
根据使用GBD的trace,命令到达return 0;但是由于某种原因,此时的“步骤”将控制权返回到已经被释放的上一行(通常是任何 Cloud::Ptr 声明)。我不确定这是因为它超出了范围,还是因为智能指针在达到返回时删除了它们,或者这些知识是否会对我有所帮助。 segFault 是一个 Double free 错误。我相信它正在被释放,因为它超出了范围,然后智能指针试图清理。 我在这里想念什么?为什么会这样?我怎样才能避免这种情况?如果你不能回答这个问题,有没有办法判断一个对象何时被释放(运行什么代码来释放)? 我确保编译器优化已关闭,以确保代码线性运行。
【问题讨论】:
-
main 中使用的任何变量的析构函数存在一些问题?
-
如果没有 area_seg 的定义,这不是一个可重现的错误。
标签: c++ segmentation-fault gdb point-cloud-library