Skip to content

Commit

Permalink
Merge pull request #3143 from xkaraman/ply_error_fix
Browse files Browse the repository at this point in the history
Add descriptive error for file not found [Issue #2766]
  • Loading branch information
SergioRAgostinho authored Jun 11, 2019
2 parents 80ecb3f + 66060b7 commit 09704a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions io/src/ply_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
#include <pcl/io/boost.h>
#include <sstream>

// https://www.boost.org/doc/libs/1_70_0/libs/filesystem/doc/index.htm#Coding-guidelines
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;

boost::tuple<std::function<void ()>, std::function<void ()> >
pcl::PLYReader::elementDefinitionCallback (const std::string& element_name, std::size_t count)
{
Expand Down Expand Up @@ -602,6 +608,12 @@ pcl::PLYReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
int data_type;
unsigned int data_idx;

if (!fs::exists (file_name))
{
PCL_ERROR ("[pcl::PLYReader::read] File (%s) not found!\n",file_name.c_str ());
return (-1);
}

if (this->readHeader (file_name, cloud, origin, orientation, ply_version, data_type, data_idx))
{
PCL_ERROR ("[pcl::PLYReader::read] problem parsing header!\n");
Expand Down Expand Up @@ -662,6 +674,13 @@ pcl::PLYReader::read (const std::string &file_name, pcl::PolygonMesh &mesh,
int data_type;
unsigned int data_idx;
polygons_ = &(mesh.polygons);

if (!fs::exists (file_name))
{
PCL_ERROR ("[pcl::PLYReader::read] File (%s) not found!\n",file_name.c_str ());
return (-1);
}

if (this->readHeader (file_name, mesh.cloud, origin, orientation, ply_version, data_type, data_idx, offset))
{
PCL_ERROR ("[pcl::PLYReader::read] problem parsing header!\n");
Expand Down

0 comments on commit 09704a5

Please sign in to comment.