【问题标题】:Confusing segFault trace using PointCloudLibrary使用 PointCloudLibrary 混淆 segFault 跟踪
【发布时间】: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


【解决方案1】:

可能正在发生的事情是cloud_cut 被破坏了两次。

这一行在栈上分配cloud_cut,当main函数返回时会被销毁:

pcl::PointCloud<pcl::PointXYZRGB> cloud_cut; 

同样,当这个智能指针被破坏时,它也会触发它所指向的对象的破坏:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr floor_cut(&cloud_cut)

因此,首先在堆上构造对象。

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多