简体   繁体   English

PCL可视化工具-退出可视化工具窗口时从本征抛出的异常

[英]PCL visualizer - exception thrown from Eigen when exit visualizer window

I tried with several PCL visualizer tutorials and attempted to combine them. 我尝试了一些PCL可视化器教程,并尝试将它们结合起来。 Basically, it generates a 3D point cloud and displays using PCL visualizer. 基本上,它会生成3D点云并使用PCL可视化工具进行显示。 The project built successful and it works. 该项目成功建立并且成功。 However, as soon as I press 'e', 'q', or pressing the close button on the top right corner to exit the program, an exception is thrown from Eigen/src/Core/util/Memory.h line 241. Any helps or explanations would be very much appreciated. 但是,一旦我按“ e”,“ q”或按右上角的关闭按钮退出程序,就会从Eigen / src / Core / util / Memory.h第241行引发异常。帮助或解释将不胜感激。 Thanks. 谢谢。

I am building using msvc-12.0, 64 bit, Boost version 1.61, PCL version 1.8, VTK version 7.1, Eigen 3.2.8 我正在使用msvc-12.0、64位,Boost版本1.61,PCL版本1.8,VTK版本7.1,本征3.2.8构建

This is the snippet from Memory.h 这是Memory.h的片段

/** \internal Frees memory allocated with aligned_malloc. */
inline void aligned_free(void *ptr)
{
  #if !EIGEN_ALIGN
    std::free(ptr);
  #elif EIGEN_MALLOC_ALREADY_ALIGNED
    std::free(ptr);  // Line 241, exception from here
  #elif EIGEN_HAS_POSIX_MEMALIGN
    std::free(ptr);
  #elif EIGEN_HAS_MM_MALLOC
    _mm_free(ptr);
  #elif defined(_MSC_VER) && (!defined(_WIN32_WCE))
    _aligned_free(ptr);
  #else
    handmade_aligned_free(ptr);
  #endif
}

Could this be some sort of memory location being freed twice? 难道这是某种内存位置被释放两次?

This is my "hello world" code: 这是我的“ hello world”代码:

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>


int main(int argc, char** argv) {

    pcl::PointCloud<pcl::PointXYZRGB> cloud;

    // Fill in the cloud data
    cloud.width = 10000;
    cloud.height = 1;
    cloud.is_dense = false;
    cloud.points.resize(cloud.width * cloud.height);

    for (size_t i = 0; i < cloud.points.size(); ++i) {
        cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].r = 256 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].g = 256 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].b = 256 * rand() / (RAND_MAX + 1.0f);

    }

    //pcl::io::savePCDFileASCII("testpcd.pcd", cloud);

    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr(&cloud);

    //visualiser
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));

    viewer->setBackgroundColor(0, 0, 0);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud_ptr, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();

    //viewer->resetCameraViewpoint("sample cloud");

    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }

    return (0);
}

Your problem is essentially this line: 您的问题本质上是以下行:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr(&cloud);

You are taking a pointer to an object on the stack, and handing it to a shared pointer. 您正在使用指向堆栈上对象的指针,并将其交给共享指针。 At the end of the scope, the shared pointer destructor then attempts to free up that memory (which it cannot do since it is on the stack, not the heap). 在作用域的末尾,共享指针析构函数然后尝试释放该内存(由于它在堆栈上,而不是在堆上,所以无法执行此操作)。 Try something like this instead: 尝试这样的事情:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>);

// Fill in the cloud data
cloud_ptr->width = 10000;
cloud_ptr->height = 1;
cloud_ptr->is_dense = false;
cloud_ptr->points.resize(cloud_ptr->width * cloud_ptr->height);

for (size_t i = 0; i < cloud_ptr->points.size(); ++i) {
    cloud_ptr->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
    cloud_ptr->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
    cloud_ptr->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    cloud_ptr->points[i].r = 256 * rand() / (RAND_MAX + 1.0f);
    cloud_ptr->points[i].g = 256 * rand() / (RAND_MAX + 1.0f);
    cloud_ptr->points[i].b = 256 * rand() / (RAND_MAX + 1.0f);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM