PCL 可视化工具 - 退出可视化工具时从 Eigen 抛出异常 window
PCL visualizer - exception thrown from Eigen when exit visualizer window
我尝试了几个 PCL 可视化工具教程并尝试将它们结合起来。基本上,它会生成 3D 点云并使用 PCL 可视化工具进行显示。该项目构建成功并且有效。但是,当我按'e'、'q'或按右上角的关闭按钮退出程序时,Eigen/src/Core/util/Memory.h第241行抛出异常。
任何帮助或解释将不胜感激。谢谢
我正在使用 msvc-12.0、64 位、Boost 版本 1.61、PCL 版本 1.8、VTK 版本 7.1、Eigen 3.2.8
这是来自 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
}
这会不会是某种内存位置被释放了两次?
这是我的 "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);
}
你的问题本质上是这一行:
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr(&cloud);
您正在获取指向堆栈上对象的指针,并将其传递给共享指针。在范围的末尾,共享指针析构函数然后尝试释放该内存(它不能这样做,因为它在堆栈上,而不是在堆上)。尝试这样的事情:
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);
}
我尝试了几个 PCL 可视化工具教程并尝试将它们结合起来。基本上,它会生成 3D 点云并使用 PCL 可视化工具进行显示。该项目构建成功并且有效。但是,当我按'e'、'q'或按右上角的关闭按钮退出程序时,Eigen/src/Core/util/Memory.h第241行抛出异常。 任何帮助或解释将不胜感激。谢谢
我正在使用 msvc-12.0、64 位、Boost 版本 1.61、PCL 版本 1.8、VTK 版本 7.1、Eigen 3.2.8
这是来自 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
}
这会不会是某种内存位置被释放了两次?
这是我的 "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);
}
你的问题本质上是这一行:
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr(&cloud);
您正在获取指向堆栈上对象的指针,并将其传递给共享指针。在范围的末尾,共享指针析构函数然后尝试释放该内存(它不能这样做,因为它在堆栈上,而不是在堆上)。尝试这样的事情:
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);
}