pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[PCL visualizer] updatePointCloud() Exception thrown Access violation reading location

Open morejiik opened this issue 6 years ago • 3 comments

Describe the bug I was following this tutorial: https://pcl.readthedocs.io/projects/tutorials/en/latest/interactive_icp.html?highlight=icp So I copied, pasted and compiled the code in: interactive_icp.cpp The code is compiled correctly and when I run it, I can see the console and the visualization window with the point clouds displayed correctly. While the programm is running, as soon as I press the space bar to let the ICP algorithm iterate, I get the following error: Exception thrown at 0x00007FFEEDA1AC6F (ntdll.dll) in interactive_icp.exe: 0xC0000005: Access violation reading location

The error appears when the class method viewer.updatePointCloud() is called from main() in interactive_icp.cpp.

Visual Studio automatically opens pcl_visualizer.hpp and highlights the exception at function

scalars->GetRange (minmax);

called inside

pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
                                                     const PointCloudColorHandler<PointT> &color_handler,
                                                     const std::string &id)

in pcl_visualizer.hpp.

Context

Following this tutorial: https://pcl.readthedocs.io/projects/tutorials/en/latest/interactive_icp.html?highlight=icp

Expected behavior

I expect that everything works fine since it is a simple and tested tutorial.

Current Behavior

I cannot iterate the ICP algorithm since the updatePointCloud() function aborts execution.

To Reproduce

Copy and paste, compile and run the code in: https://pcl.readthedocs.io/projects/tutorials/en/latest/interactive_icp.html?highlight=icp

Screenshots/Code snippets

immagine

while loop contained in main() function in interactive_icp.cpp. Please notice the presence of viewer.updateCloudPoint()

while (!viewer.wasStopped())
    {
        viewer.spinOnce();

        // The user pressed "space" :
        if (next_iteration)
        {
            // The Iterative Closest Point algorithm
            time.tic();
            icp.align(*cloud_icp);
            std::cout << "Applied 1 ICP iteration in " << time.toc() << " ms" << std::endl;

            if (icp.hasConverged())
            {
                printf("\033[11A");  // Go up 11 lines in terminal output.
                printf("\nICP has converged, score is %+.0e\n", icp.getFitnessScore());
                std::cout << "\nICP transformation " << ++iterations << " : cloud_icp -> cloud_in" << std::endl;
                transformation_matrix *= icp.getFinalTransformation().cast<double>();  // WARNING /!\ This is not accurate! For "educational" purpose only!
                print4x4Matrix(transformation_matrix);  // Print the transformation between original pose and current pose

                ss.str("");
                ss << iterations;
                std::string iterations_cnt = "ICP iterations = " + ss.str();
                viewer.updateText(iterations_cnt, 10, 60, 16, txt_gray_lvl, txt_gray_lvl, txt_gray_lvl, "iterations_cnt");
                viewer.updatePointCloud(cloud_icp, cloud_icp_color_h, "cloud_icp_v2");
            }
            else
            {
                PCL_ERROR("\nICP has not converged.\n");
                return (-1);
            }
        }
        next_iteration = false;
    }

Your Environment (please complete the following information):

  • OS: Win10 x64
  • Compiler: CMake + Visual Studio 16 2019
  • PCL Version: PCL-1.10.0-AllInOne-msvc2019-win64 EDIT

Additional context

Once I get the error for the first time, if i hit the continue button on my Visual Studio interface I get:

Unhandled exception at 0x00007FFEEDA1AC6F (ntdll.dll) in interactive_icp.exe: 0xC0000005: Access violation reading location 0x0000000000000024.

morejiik avatar Jul 17 '20 10:07 morejiik

I tried a workaround in the meantime, so I wrote my updateCloud function:

void updateCloud
(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_color_handler, pcl::visualization::PCLVisualizer& viewer, const std::string id, const int point_size)
{
    viewer.removePointCloud(id);
    viewer.addPointCloud(cloud, cloud_color_handler, id);
    viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, point_size, id);

    return;
}

and with some slightly changes I used it instead of the pcl updatePointCloud(), in the same loop.

With my surprise I got another exception: Unhandled exception at 0x00007FFEEDAD9229 (ntdll.dll) in interactive_icp.exe: 0xC0000374: Heap danneggiato (parameters: 0x00007FFEEDB427F0). (where "Heap danneggiato" means "damaged/corrupted heap")

that is caused by the line:

viewer.removePointCloud(id);

If I hit continue a couple of times, the exception goes away and the program runs without problems.

morejiik avatar Jul 17 '20 12:07 morejiik

I meet this error too! Why does official sample occur such problem.

ffy747426112 avatar Aug 28 '20 03:08 ffy747426112

This is fixed in https://github.com/PointCloudLibrary/pcl/pull/4017 and part of 1.11 release.

larshg avatar Jul 11 '21 10:07 larshg