'Unhandled Exception when reading in a pcd file

I am using the pcl library , with visual studio 2019 on windows. Unfortunately I am unable to load the demo file that I downloaded even with the full path to the file.

The exception occurs at reader.read("table_scene_lms400.pcd", *cloud); // Remember to download the file first!

here is my code:

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>

int
main(int argc, char** argv)
{
    pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2());
    pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2());

    // Fill in the cloud data
    pcl::PCDReader reader;
    // Replace the path below with the path where you saved your file
    reader.read("table_scene_lms400.pcd", *cloud); // Remember to download the file first!

    std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height
        << " data points (" << pcl::getFieldsList(*cloud) << ")." << std::endl;

    // Create the filtering object
    pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
    sor.setInputCloud(cloud);
    sor.setLeafSize(0.01f, 0.01f, 0.01f);
    sor.filter(*cloud_filtered);

    std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height
        << " data points (" << pcl::getFieldsList(*cloud_filtered) << ")." << std::endl;

    pcl::PCDWriter writer;
    writer.write("table_scene_lms400_downsampled.pcd", *cloud_filtered,
        Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(), false);

    return (0);
}

the exception is: Unhandled exception at 0x00007FFB65A94F69 in PCL_Down_Sample_Point_Clouds.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000377BBFE9A0.

pcl


Solution 1:[1]

To fix this I had to go to my settings and link the debug version of pcl_io. The debug version was pcl_iod.lib. This setting ,in visual studio, is under:

Configuration Properties
->Linker
->Input
->Additional Dependencies

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Csala