Search code examples
c++point-cloud-librarypoint-clouds

PCL loadPCDFile() error


Once I successfuly compiled PCL with Visual C++ 2013 x64, I am totally stacked trying to debug following error. When loading .pcd file using pcl::io::loadPCDFile(), I've got a debug assertion failed followed by some access violation errors.

std::string fileName = "E:/C PROJECTS/models/generated.pcd";

    target_cloud.reset(new Cloud());

    if (pcl::io::loadPCDFile(model_filename_, *target_cloud) == -1) //* load the file
    {
        PCL_ERROR("Couldn't read .pcd file \n");
        return (-1);
    }

enter image description here

enter image description here


Solution

  • This error is an (almost) sure sign that you are linking two different CRT's (C Runtime libraries) to your program. Each CRT has its own heap for memory allocations. Something is being freed by one CRT which was actually allocated by the other CRT, and when the freeing CRT tries to add the freed memory to its own heap, finds out that it doesn't belong there, causing an assert.

    Probably, your PCL is compiled to use a different CRT from the one your project is using. Open the PCL solution, open project settings, and check the setting at C/C++ -> Code Generation -> Runtime Library. Then do the same in in your own project's solution, check that they match.

    You also need to have compiled both PCL and your project with the same version of Visual Studio (since each new version appears to come with a new set of CRTs...sigh).

    As a last resort, you can also check the Output window and note which DLLs are being loaded, and see if you can spot multiple incompatible CRTs. You can find info on the filenames at: https://support.microsoft.com/en-us/kb/140584 or using google.

    If you really want to use a specific CRT for your project, you'd have to recompile PCL to use the CRT you want.