問題解決: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:回答前帶有綠色對號的基本為經過人們驗證的正確解決方案)。
相關文章
- 解決windows下WslRegisterDistribution failed with error: 0x80070050的問題WindowsAIError
- VS C++ 出現debug assertion failed彈框,怎麼定位程式碼C++AI
- 解決父母的養老問題,有哪些好經驗值得分享?
- tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [0] [Op:Assert] namePythonFrameworkErrorAI
- 關於Failed to resolve的問題解決AI
- 解決C3P0在Linux下Failed to get local InetAddress for VMID問題LinuxAI
- Debug經驗
- 解決Spring Boot測試方法Failed to load ApplicationContext問題Spring BootAIAPPContext
- [轉]經驗分享:微信小程式外包接單常見問題及流程微信小程式
- Mac OSX系統homebrew update Fetching failed問題解決方案MacAI
- Java 應用壓測效能問題定位經驗分享Java
- px、em和rem實戰經驗REM
- DDD經驗:分享工作,分享決策 – Jessitron
- Harbor搭建及配置 問題解決
- Git常見問題及解決Git
- 跨域問題及解決方案跨域
- redis安裝及問題解決Redis
- 7 種方案解決移動端1px邊框的問題
- PHP報錯getimagesize(): SSL operation failed with code 1問題解決方案PHPAI
- react解決ios微信分享的問題ReactiOS
- 【技術分享】如何使用FMEA解決問題?
- IPython的安裝及問題解決Python
- WordPress:常見問題及解決方案
- django安裝xadmin及問題解決Django
- Nacos 常見問題及解決方法
- UltraEdit常見問題及解決教程
- 窮舉法解決0/1揹包問題——pythonPython
- 【知識分享】伺服器常見異常問題及解決辦法伺服器
- command 'gcc' failed with exit status 1錯誤問題的解決辦法GCAI
- Doris建立表報錯Failed to find enough host with storage medium問題解決AI
- 解決requests庫中SSL驗證問題
- AI|經常崩潰的問題解決AI
- TCP通訊之經典問題解決TCP
- 【經驗分享】Python實現UI自動化難點問題PythonUI
- flutter安裝詳解--初體驗--問題解決Flutter
- 分享net面試題和經驗面試題
- 問卷調查中常見問題及解決方法
- 快取三大問題及解決方案快取