pcl spin bad_alloc [closed]

asked 2013-10-15 01:02:45 -0600

pmarinplaza gravatar image

updated 2014-01-28 17:18:14 -0600

ngrennan gravatar image
ROS: fuerte
Ubuntu 12.04
Intel Core 2 Duo 3000+

Hello Team, I am having problems with PCL visualizer and ROS about work flow. The main problem is when I call viewer->spinOnce(); The fact is standalone works great, but when I want put inside a class and use it in gui program appear std::bad_alloc. I read it is because memory overflow.

I give you the related code of my gui with pcl with QtDessigner

KinectGui.h

namespace Ui {
class KinectGui;
}

class KinectGui : public QWidget
{
    Q_OBJECT

public:
    explicit KinectGui(QWidget *parent = 0);
    ~KinectGui();
    void start();
...
private:              
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_;
    void cloudCallback(const sensor_msgs::PointCloud2ConstPtr& input);
...
}

kinectGui.cpp

KinectGui::KinectGui(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::KinectGui)
{
    ui->setupUi(this);          
    viewer_ = new pcl::visualization::PCLVisualizer ("3D Viewer");
    viewer_->setBackgroundColor (0, 0, 0);
    viewer_->addCoordinateSystem (1.0);
    viewer_->initCameraParameters ();        
    cloud_sub_ = nh.subscribe("/camera/depth/points", 10, &KinectGui::cloudCallback, this);
}

KinectGui::~KinectGui()
{
    delete ui;   
}



  void KinectGui::cloudCallback(const sensor_msgs::PointCloud2ConstPtr& input){
           pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
           pcl::fromROSMsg(*input,*cloud);

           viewer_->removePointCloud();
           viewer_->addPointCloud<pcl::PointXYZ>(cloud);
           viewer_->spinOnce();
        }

The result of running this is when some pointCloud2 income by topic, appear one message and close the whole program:

$ rosrun guiWidgets guiLSI 
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

What Am I doing wrong?

Best regards and thanks for your help.

edit retag flag offensive reopen merge delete

Closed for the following reason PCL Question: The PCL community prefers to answer questions at http://www.pcl-users.org/ by tfoote
close date 2015-03-09 17:09:28.207430