问题解决:shared_ptr Assertion px != 0 failed 及debug经验分享

问题解决:shared_ptr Assertion px != 0 failed及debug经验分享

问题详细描述:

/usr/include/boost/smart_ptr/shared_ptr.hpp:646: typename boost::detail::sp_dereference::type boost::shared_ptr::operator*() const [with T = pcl::PointCloudpcl::pointxyz; typename boost::detail::sp_dereference::type = pcl::PointCloudpcl::pointxyz&]: Assertion `px != 0’ failed. Aborted (core dumped)

问题原因:

在使用boost::shared_ptr之前未进行初始化或者未正确初始化

错误代码示例:
class Listener
{

public:
	#在这里使用cloud_passthrough时未正确初始化
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_passthrough;

    void callback(const sensor_msgs::PointCloud2ConstPtr& kinect_output);

};
// end class

void Listener::callback(const sensor_msgs::PointCloud2ConstPtr& kinect_output)
{
    pcl::PCLPointCloud2::Ptr pc2 (new pcl::PCLPointCloud2());

    pcl_conversions::toPCL (*kinect_output, *pc2);

    pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());

    pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
    sor.setInputCloud (pc2);
    sor.setLeafSize(0.01f,0.01f,0.01f);
    sor.filter(*cloud_filtered);// filter the point cloud
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloudXYZ (new pcl::PointCloud<pcl::PointXYZ>);//object cloud for point cloud type XYZ
    pcl::fromPCLPointCloud2(*cloud_filtered,*cloudXYZ);

    //create passthrough filter object
    pcl::PassThrough<pcl::PointXYZ> pass;
    pass.setInputCloud (cloudXYZ);
    pass.setFilterFieldName("z");
    pass.setFilterLimits(0.5, 1.5);
    pass.filter(*cloud_passthrough);
}

int main (int argc, char **argv)
{
    ros::init (argc, argv, "PointCloud2_to_pointCloudXYZ");

    ros::NodeHandle nh;

    Listener listener;

    ros::Publisher pub = nh.advertise<pcl::PointCloud<pcl::PointXYZ> >("/filtered", 1000);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    cloud -> points = listener.cloud_passthrough->points;
    ros::Rate loop_rate(10);    
    ros::Subscriber sub = nh.subscribe <sensor_msgs::PointCloud2> ("/camera/depth/points",1000,&Listener::callback, &listener);
    while (ros::ok())
    {
        pub.publish (cloud);
        ros::spinOnce();
        loop_rate.sleep();
    }//end while loop   
    return 0;
}//end main
正确初始化示例:
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_passthrough(new pcl::PointCloud<pcl::PointXYZ>);
boost::shared_ptr<Obj> obj;
obj->Something(); // assertion failed

boost::shared_ptr<Obj> obj(new Obj);
obj->Something(); // ok
最后分享一个debug的经验,能够使用科学上网的童鞋,可以Google搜索stack overflow网站,针对自己遇到的问题进行搜索,一般情况下均可以搜到对应的解决方法(ps:回答前带有绿色对号的基本为经过人们验证的正确解决方案)。
  • 12
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值