I tried with several PCL visualizer tutorials and attempted to combine them. Basically, it generates a 3D point cloud and displays using PCL visualizer. 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. 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
This is the snippet from 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:
#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);
}