PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.83k stars 4.6k forks source link

[Features] Unhandled exception in "pcl_features.dll" #4916

Open suomi-miartem opened 3 years ago

suomi-miartem commented 3 years ago

Describe the bug

An error of unhandled exception in "pcl_features.dll" occures while running my program.

Context

I tried to run a bit modified demonstrational example of PCL Visualizer and an error had occured while program was running.

Expected behavior

When you enter a letter, the associated rendering method is executed.

Current Behavior

After running the program, the error "Unhandled exception at 0x00007FFAC37E029B (pcl_features.dll) in [example_name].exe: 0xC000001D: Illegal Instruction." appears, and debugger prints "the symbol file was not loaded". Moreover, the error manifests itself precisely on version 1.12.0 - in the previous version (1.11.1) everything works fine.

To Reproduce

  1. Download and install PCL 1.12.0 all-in-one 64x version with all third-party modules;
  2. Make project via Cmake using Cmake code from this tutorial;
  3. Build the solution in x64-release configuration;
  4. Copy-paste my a bit modified code of tutorial example into your main [file_name].cpp file;
  5. Run this and catch the bug :)

My code:

#include <iostream>
#include <thread>

#include <pcl/common/angles.h> // for pcl::deg2rad
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>

using namespace std;
using namespace std::chrono_literals;

// --------------
// -----Help-----
// --------------
void printHint() {
    std::cout
        << "Options:\n"
        << "-------------------------------------------\n"
        << "-h           this help\n"
        << "-s           Simple visualisation example\n"
        << "-r           RGB colour visualisation example\n"
        << "-c           Custom colour visualisation example\n"
        << "-n           Normals visualisation example\n"
        << "-a           Shapes visualisation example\n"
        << "-v           Viewports example\n"
        << "-i           Interaction Customization example\n"
        << "\n\n";
}

pcl::visualization::PCLVisualizer::Ptr simpleVis(pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
    // --------------------------------------------
    // -----Open 3D viewer and add point cloud-----
    // --------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addPointCloud<pcl::PointXYZ>(cloud, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();
    return (viewer);
}

pcl::visualization::PCLVisualizer::Ptr rgbVis(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud)
{
    // --------------------------------------------
    // -----Open 3D viewer and add point cloud-----
    // --------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud, rgb, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();
    return (viewer);
}

pcl::visualization::PCLVisualizer::Ptr customColourVis(pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
    // --------------------------------------------
    // -----Open 3D viewer and add point cloud-----
    // --------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 0, 255, 0);
    viewer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();
    return (viewer);
}

pcl::visualization::PCLVisualizer::Ptr normalsVis(
    pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud, pcl::PointCloud<pcl::Normal>::ConstPtr normals)
{
    // --------------------------------------------------------
    // -----Open 3D viewer and add point cloud and normals-----
    // --------------------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud, rgb, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
    viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(cloud, normals, 10, 0.05, "normals");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();
    return (viewer);
}

pcl::visualization::PCLVisualizer::Ptr shapesVis(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud)
{
    // --------------------------------------------
    // -----Open 3D viewer and add point cloud-----
    // --------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud, rgb, "sample cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();

    //------------------------------------
    //-----Add shapes at cloud points-----
    //------------------------------------
    viewer->addLine<pcl::PointXYZRGB>((*cloud)[0],
        (*cloud)[cloud->size() - 1], "line");
    viewer->addSphere((*cloud)[0], 0.2, 0.5, 0.5, 0.0, "sphere");

    //---------------------------------------
    //-----Add shapes at other locations-----
    //---------------------------------------
    pcl::ModelCoefficients coeffs;
    coeffs.values.push_back(0.0);
    coeffs.values.push_back(0.0);
    coeffs.values.push_back(1.0);
    coeffs.values.push_back(0.0);
    viewer->addPlane(coeffs, "plane");
    coeffs.values.clear();
    coeffs.values.push_back(0.3);
    coeffs.values.push_back(0.3);
    coeffs.values.push_back(0.0);
    coeffs.values.push_back(0.0);
    coeffs.values.push_back(1.0);
    coeffs.values.push_back(0.0);
    coeffs.values.push_back(5.0);
    viewer->addCone(coeffs, "cone");

    return (viewer);
}

pcl::visualization::PCLVisualizer::Ptr viewportsVis(
    pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud, pcl::PointCloud<pcl::Normal>::ConstPtr normals1, pcl::PointCloud<pcl::Normal>::ConstPtr normals2)
{
    // --------------------------------------------------------
    // -----Open 3D viewer and add point cloud and normals-----
    // --------------------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->initCameraParameters();

    int v1(0);
    viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
    viewer->setBackgroundColor(0, 0, 0, v1);
    viewer->addText("Radius: 0.01", 10, 10, "v1 text", v1);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud, rgb, "sample cloud1", v1);

    int v2(0);
    viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
    viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
    viewer->addText("Radius: 0.1", 10, 10, "v2 text", v2);
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> single_color(cloud, 0, 255, 0);
    viewer->addPointCloud<pcl::PointXYZRGB>(cloud, single_color, "sample cloud2", v2);

    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud1");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud2");
    viewer->addCoordinateSystem(1.0);

    viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(cloud, normals1, 10, 0.05, "normals1", v1);
    viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(cloud, normals2, 10, 0.05, "normals2", v2);

    return (viewer);
}

unsigned int text_id = 0;
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent& event,
    void* viewer_void)
{
    pcl::visualization::PCLVisualizer* viewer = static_cast<pcl::visualization::PCLVisualizer*> (viewer_void);
    if (event.getKeySym() == "r" && event.keyDown())
    {
        std::cout << "r was pressed => removing all text" << std::endl;

        char str[512];
        for (unsigned int i = 0; i < text_id; ++i)
        {
            sprintf(str, "text#%03d", i);
            viewer->removeShape(str);
        }
        text_id = 0;
    }
}

void mouseEventOccurred(const pcl::visualization::MouseEvent& event,
    void* viewer_void)
{
    pcl::visualization::PCLVisualizer* viewer = static_cast<pcl::visualization::PCLVisualizer*> (viewer_void);
    if (event.getButton() == pcl::visualization::MouseEvent::LeftButton &&
        event.getType() == pcl::visualization::MouseEvent::MouseButtonRelease)
    {
        std::cout << "Left mouse button released at position (" << event.getX() << ", " << event.getY() << ")" << std::endl;

        char str[512];
        sprintf(str, "text#%03d", text_id++);
        viewer->addText("clicked here", event.getX(), event.getY(), str);
    }
}

pcl::visualization::PCLVisualizer::Ptr interactionCustomizationVis()
{
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addCoordinateSystem(1.0);

    viewer->registerKeyboardCallback(keyboardEventOccurred, (void*)viewer.get());
    viewer->registerMouseCallback(mouseEventOccurred, (void*)viewer.get());

    return (viewer);
}

// --------------
// -----Main-----
// --------------
int
main(int argc, char** argv)
{
    // ------------------------------------
    // -----Create example point cloud-----
    // ------------------------------------
    pcl::PointCloud<pcl::PointXYZ>::Ptr basic_cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>);
    std::cout << "Generating example point clouds.\n\n";
    // We're going to make an ellipse extruded along the z-axis. The colour for
    // the XYZRGB cloud will gradually go from red to green to blue.
    std::uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
        for (float angle(0.0); angle <= 360.0; angle += 5.0)
        {
            pcl::PointXYZ basic_point;
            basic_point.x = 0.5 * std::cos(pcl::deg2rad(angle));
            basic_point.y = sinf(pcl::deg2rad(angle));
            basic_point.z = z;
            basic_cloud_ptr->points.push_back(basic_point);

            pcl::PointXYZRGB point;
            point.x = basic_point.x;
            point.y = basic_point.y;
            point.z = basic_point.z;
            std::uint32_t rgb = (static_cast<std::uint32_t>(r) << 16 |
                static_cast<std::uint32_t>(g) << 8 | static_cast<std::uint32_t>(b));
            point.rgb = *reinterpret_cast<float*>(&rgb);
            point_cloud_ptr->points.push_back(point);
        }
        if (z < 0.0)
        {
            r -= 12;
            g += 12;
        }
        else
        {
            g -= 12;
            b += 12;
        }
    }
    basic_cloud_ptr->width = basic_cloud_ptr->size();
    basic_cloud_ptr->height = 1;
    point_cloud_ptr->width = point_cloud_ptr->size();
    point_cloud_ptr->height = 1;

    // ----------------------------------------------------------------
    // -----Calculate surface normals with a search radius of 0.05-----
    // ----------------------------------------------------------------
    pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne;
    ne.setInputCloud(point_cloud_ptr);
    pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZRGB>());
    ne.setSearchMethod(tree);
    pcl::PointCloud<pcl::Normal>::Ptr cloud_normals1(new pcl::PointCloud<pcl::Normal>);
    ne.setRadiusSearch(0.05);
    ne.compute(*cloud_normals1);

    // ---------------------------------------------------------------
    // -----Calculate surface normals with a search radius of 0.1-----
    // ---------------------------------------------------------------
    pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2(new pcl::PointCloud<pcl::Normal>);
    ne.setRadiusSearch(0.1);
    ne.compute(*cloud_normals2);

    bool simple(false), rgb(false), custom_c(false), normals(false),
        shapes(false), viewports(false), interaction_customization(false);

    while (true) {
        // --------------------------------------
        // -----Parse Command Line Arguments-----
        // --------------------------------------
        string s;
        cin >> s;

        if (s == "h")
        {
            printHint();
        }

        if (s == "s")
        {
            simple = true;
            std::cout << "Simple visualisation example\n";
            break;
        }
        else if (s == "c")
        {
            custom_c = true;
            std::cout << "Custom colour visualisation example\n";
            break;
        }
        else if (s == "r")
        {
            rgb = true;
            std::cout << "RGB colour visualisation example\n";
            break;
        }
        else if (s == "n")
        {
            normals = true;
            std::cout << "Normals visualisation example\n";
            break;
        }
        else if (s == "a")
        {
            shapes = true;
            std::cout << "Shapes visualisation example\n";
            break;
        }
        else if (s == "v")
        {
            viewports = true;
            std::cout << "Viewports example\n";
            break;
        }
        else if (s == "i")
        {
            interaction_customization = true;
            std::cout << "Interaction Customization example\n";
            break;
        }
    }

    pcl::visualization::PCLVisualizer::Ptr viewer;
    if (simple)
    {
        viewer = simpleVis(basic_cloud_ptr);
    }
    else if (rgb)
    {
        viewer = rgbVis(point_cloud_ptr);
    }
    else if (custom_c)
    {
        viewer = customColourVis(basic_cloud_ptr);
    }
    else if (normals)
    {
        viewer = normalsVis(point_cloud_ptr, cloud_normals2);
    }
    else if (shapes)
    {
        viewer = shapesVis(point_cloud_ptr);
    }
    else if (viewports)
    {
        viewer = viewportsVis(point_cloud_ptr, cloud_normals1, cloud_normals2);
    }
    else if (interaction_customization)
    {
        viewer = interactionCustomizationVis();
    }

    //--------------------
    // -----Main loop-----
    //--------------------
    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);
        std::this_thread::sleep_for(100ms);
    }
}

Your Environment (please complete the following information):

Possible Solution

I suppose "pcl_features.dll" was corrupted while making new release.

mvieth commented 3 years ago

I tried to reproduce this on Ubuntu 21.04, but couldn't. Maybe it only appears on Windows, but could you describe exactly, which letters you are passing to the program to trigger the error? Any letter or only specific ones? Could you perhaps even try to find out in which line exactly the error happens (e.g. with simple prints)?

suomi-miartem commented 3 years ago

@mvieth , it doesn't depend of letter type. Maybe I should notice that this bug appears when a debugger steps on line with any [features/normal3d] object before command line parsing part (lines 273-279, 284-286). I downloaded 12.0.0 PCL twice, but every time this bug with normals appeared...

mvieth commented 3 years ago

Can you try another tutorial that uses NormalEstimation, e.g. this one?

larshg commented 3 years ago

@suomi-miartem Could you try enable AVX on your project. I just ran your code and I cannot get it to crash.

Could also be a debug/release mismatch - you can see this using the dependency walker.

suomi-miartem commented 3 years ago

@mvieth , I ran the code from your example, but in Release mode it gave me the same "unhandled exception in features.dll" error. The only difference was that in my code, when starting the project in Debug mode, the debugger stopped at line 227 in the "feature.hpp" file (PCL 1.12.0 \ include \ pcl-1.12 \ pcl \ features \ impl \ feature. hpp), and in the code from your example - on the 281st line in the file "pcd_io.hpp" (PCL 1.12.0 \ include \ pcl-1.12 \ pcl \ io \ pcd_io.h)...

@larshg , AVX gave me nothing :( How can I fix the version mismatch if this is indeed the cause of my problem (I'm not sure about this yet)? Also, dependency walker hangs while analyzing πŸ˜…

Alright, I'll just try to use previous PCL version (1.11.1), but that 1.12.0 bug is still actual.

larshg commented 3 years ago

Even though this answer is quite old, it could still be relevant. https://stackoverflow.com/questions/14401024/unhandled-exception-at-0x52f9e470-in-project1-exe-0xc000001d-illegal-instruc

What CPU do you have?

Can you post a screenshot of the stack frame when the exception occours?

suomi-miartem commented 3 years ago

@larshg , Jeez, I am pretty grateful to you for this link! IDK what kind of magic do you use to find this relevant thread 😁 I will report about my success to work without SSE instructions (I really have AMD processor) tomorrow

larshg commented 3 years ago

Oki. The All-In-One installer is build with both SSE and AVX, so you would have to compile PCL yourself, to have it without those instructions.

If you want you can try follow this guideline https://github.com/larshg/pcl/blob/UpdateWindowsTutorial/doc/tutorials/content/pcl_vcpkg_windows.rst To install dependencies or even PCl using VCPKG.

You might still need to checkout the 1.12 PR on VCPKG if it is not merged yet.

Else you probably need to stay on 1.11 :-)

suomi-miartem commented 3 years ago

Nah, compiling PCL by hand turned out to be too time consuming for me, so I scored it and went back to version 1.11.1. Nevertheless, if someone had a similar problem after updating the version of the library, then they can participate in this thread. Therefore, I close the issue.

larshg commented 3 years ago

Could you try using a tool like this https://docs.microsoft.com/en-us/sysinternals/downloads/coreinfo

And post the results. Then we could have a look if the SSE or AVX is supported?

And lets keep it open, as there is no confirmation yet what the error is, nor yet a solution.

suomi-miartem commented 3 years ago

Here is my SSE/AVX support information. As you can see, my PC supports them: SSE Supports Streaming SIMD Extensions SSE2 Supports Streaming SIMD Extensions 2 SSE3 Supports Streaming SIMD Extensions 3 SSSE3 Supports Supplemental SIMD Extensions 3 SSE4a Supports Streaming SIMDR Extensions 4a SSE4.1 Supports Streaming SIMD Extensions 4.1 SSE4.2 * Supports Streaming SIMD Extensions 4.2

AVX * Supports AVX instruction extensions AVX2 - Supports AVX2 instruction extensions AVX-512-F - Supports AVX-512 Foundation instructions AVX-512-DQ - Supports AVX-512 double and quadword instructions AVX-512-IFAMA - Supports AVX-512 integer Fused multiply-add instructions AVX-512-PF - Supports AVX-512 prefetch instructions AVX-512-ER - Supports AVX-512 exponential and reciprocal instructions AVX-512-CD - Supports AVX-512 conflict detection instructions AVX-512-BW - Supports AVX-512 byte and word instructions AVX-512-VL - Supports AVX-512 vector length instructions

larshg commented 3 years ago

Thanks. That rules out the instruction set then.

Could you try launch it in debug and post the stacktrace when it crash?

jackjansen commented 2 years ago

Chiming in with a different problem, but it may be related. For me PCL 1.12.1 all-in-one installer fails on 2 machines (works fine on many others I'm using):

The problem is that pcl_io.dll fails to load. Running under the debugger (on the Parallels VM) I see that it gets an illegal instruction (I presume in the initialization routine of pcl_io.dll, but I cannot check). The instruction is a VPXOR instruction.

Tried running in Debug (because then I have the libpcl .pdb files, and I hoped that would give me a usable stack trace): no problem, everything runs fine.

Reverted to PCL 1.11.1: everything runs fine.

I realise this is not much of a bug report, I'm posting it mainly (and posting it with this error report) in the hope it'll spark an "aha" with the pcl developers.