Ask Your Question

Exception thrown when deserializing message of length [453372] from [/my_filter]: std::bad_alloc

asked 2020-10-12 03:37:56 -0500

aravindsaiUR gravatar image

updated 2022-05-23 09:11:26 -0500

lucasw gravatar image


I am trying to publish PCL point clouds which are obtained from velodyne point cloud. The program is compiled and running. I can even see the height and width information from the PCL point clouds but when I open RVIZ and visualize the published PCL point clouds, I get this message.

[ERROR] [1602489936.969819842]: Exception thrown when deserializing message of length [453372] from [/my_filter]: std::bad_alloc

ros::Publisher ptc_pub;
void callback(const ImageConstPtr& image, const PointCloud2ConstPtr& pt_cloud)
  pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
  pcl::fromROSMsg(*pt_cloud, pcl_cloud);
  int PCLwidth = pcl_cloud.width;
  int PCLheight = pcl_cloud.height;
  cout<< "width = "<<PCLwidth <<endl;
  cout<< "height"<<PCLheight <<endl;
  // ros::spinOnce();
  // loop_rate.sleep();
int main(int argc, char** argv)
  ros::init(argc, argv, "my_filter");
  ros::NodeHandle node_;

  ros::Publisher ptc_pub = node_.advertise<PointCloud>("pcl_pts", 1);
  // ros::Rate loop_rate(10);

  message_filters::Subscriber<Image> img_sub(node_, "cam_1/color/image_raw", 1);
  message_filters::Subscriber<PointCloud2> pointcloud_sub(node_, "velodyne_points", 1);

  typedef sync_policies::ApproximateTime<Image, PointCloud2> MySyncPolicy;
  Synchronizer<MySyncPolicy> sync(MySyncPolicy(10),img_sub, pointcloud_sub);
  sync.registerCallback(boost::bind(&callback, _1,_2));
  return 0;

What I am doing wrong ? My guess is that I have placed the publisher wrong or is it something else ? I am new to ROS and cpp. Any suggestion will be really useful.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-05-19 08:10:40 -0500

miura gravatar image

As you guessed, the type of the variable you are giving to the publisher is different; it will convert to sensor_msgs::PointCloud instead of pcl::PointCloud, so try the following

void callback(const ImageConstPtr& image, const PointCloud2ConstPtr& pt_cloud)
  PointCloud pt_cloud1;
  convertPointCloud2ToPointCloud(*pt_cloud, pt_cloud1);

ref: convertPointCloud2ToPointCloud

edit flag offensive delete link more



You're right. That was the issue. Thanks :)

aravindsaiUR gravatar image aravindsaiUR  ( 2021-05-19 09:00:29 -0500 )edit

You're welcome.

miura gravatar image miura  ( 2021-05-19 09:07:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-10-12 03:37:56 -0500

Seen: 367 times

Last updated: May 19 '21