Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pcl_registration] ICP align broken in Release in new PCL version #6011

Closed
LuukvandenBent opened this issue Apr 16, 2024 · 8 comments
Closed

Comments

@LuukvandenBent
Copy link

I am trying to do a simple point-to-point ICP using the newest PCL 1.14 from https://github.com/PointCloudLibrary/pcl/releases. I am running on windows with MSVC2022. When i run in Debug mode the code works as expected, however when switching to Release mode i get the following error "Exception thrown at 0x00007FF9C4399E82 (pcl_registration.dll) in ICPTest.exe: 0xC0000005: Access violation reading location 0x0000000000000000." Which happens at registration.hpp on line 214 at deinitCompute().

My code is as follows:

#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
#include <Eigen/Core>
#include <iostream>
#include <vector>
#include <string>
#include <iostream>

int main()
{
	Eigen::Matrix4f initialGuess;
	initialGuess << -0.79772884, -0.602947, 0.0091452301, 0.54087126,
		0.60219932, -0.79734558, -0.039949566, 0.29958388,
		0.031379379, -0.02636167, 0.99915987, 4.0332251,
		0, 0, 0, 1;

	pcl::PointXYZ point1(0.0964, 0.0964, 0);
	pcl::PointXYZ point2(0.1928, 0.0964, 0);
	pcl::PointXYZ point3(0.2892, 0.0964, 0);
	pcl::PointXYZ point4(0.3856, 0.0964, 0);
	pcl::PointXYZ point5(0.0964, 0.1928, 0);
	pcl::PointXYZ point6(0.1928, 0.1928, 0);
	pcl::PointXYZ point7(0.2892, 0.1928, 0);
	pcl::PointXYZ point8(0.3856, 0.1928, 0);
	pcl::PointXYZ point9(0.0964, 0.2892, 0);
	pcl::PointXYZ point10(0.1928, 0.2892, 0);
	pcl::PointXYZ point11(0.2892, 0.2892, 0);
	pcl::PointXYZ point12(0.3856, 0.2892, 0);
	pcl::PointXYZ point13(0.0964, 0.3856, 0);
	pcl::PointXYZ point14(0.1928, 0.3856, 0);
	pcl::PointXYZ point15(0.2892, 0.3856, 0);
	pcl::PointXYZ point16(0.3856, 0.3856, 0);

	auto pcBoardLocalPoints = std::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
	pcBoardLocalPoints->push_back(point1);
	pcBoardLocalPoints->push_back(point2);
	pcBoardLocalPoints->push_back(point3);
	pcBoardLocalPoints->push_back(point4);
	pcBoardLocalPoints->push_back(point5);
	pcBoardLocalPoints->push_back(point6);
	pcBoardLocalPoints->push_back(point7);
	pcBoardLocalPoints->push_back(point8);
	pcBoardLocalPoints->push_back(point9);
	pcBoardLocalPoints->push_back(point10);
	pcBoardLocalPoints->push_back(point11);
	pcBoardLocalPoints->push_back(point12);
	pcBoardLocalPoints->push_back(point13);
	pcBoardLocalPoints->push_back(point14);
	pcBoardLocalPoints->push_back(point15);
	pcBoardLocalPoints->push_back(point16);

	pcl::PointXYZ point17(0.405362, 0.280499, 4.02927);
	pcl::PointXYZ point18(0.328634, 0.338359, 4.03182);
	pcl::PointXYZ point19(0.251768, 0.396457, 4.03524);
	pcl::PointXYZ point20(0.174904, 0.454478, 4.03862);
	pcl::PointXYZ point21(0.347402, 0.203805, 4.02744);
	pcl::PointXYZ point22(0.270521, 0.261779, 4.03071);
	pcl::PointXYZ point23(0.193816, 0.319653, 4.03256);
	pcl::PointXYZ point24(0.116859, 0.377736, 4.03639);
	pcl::PointXYZ point25(0.289344, 0.126809, 4.02492);
	pcl::PointXYZ point26(0.212497, 0.184975, 4.02838);
	pcl::PointXYZ point27(0.13569, 0.242913, 4.0307);
	pcl::PointXYZ point28(0.0588851, 0.300938, 4.03391);
	pcl::PointXYZ point29(0.231334, 0.0502003, 4.02308);
	pcl::PointXYZ point30(0.154418, 0.108227, 4.02622);
	pcl::PointXYZ point31(0.0776226, 0.166133, 4.02866);
	pcl::PointXYZ point32(0.000697852, 0.224108, 4.0321);

	auto pcBoardCameraPoints = std::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
	pcBoardCameraPoints->push_back(point17);
	pcBoardCameraPoints->push_back(point18);
	pcBoardCameraPoints->push_back(point19);
	pcBoardCameraPoints->push_back(point20);
	pcBoardCameraPoints->push_back(point21);
	pcBoardCameraPoints->push_back(point22);
	pcBoardCameraPoints->push_back(point23);
	pcBoardCameraPoints->push_back(point24);
	pcBoardCameraPoints->push_back(point25);
	pcBoardCameraPoints->push_back(point26);
	pcBoardCameraPoints->push_back(point27);
	pcBoardCameraPoints->push_back(point28);
	pcBoardCameraPoints->push_back(point29);
	pcBoardCameraPoints->push_back(point30);
	pcBoardCameraPoints->push_back(point31);
	pcBoardCameraPoints->push_back(point32);

	pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
	icp.setInputSource(pcBoardLocalPoints);
	icp.setInputTarget(pcBoardCameraPoints);
	icp.setEuclideanFitnessEpsilon(1e-8);
	icp.setMaximumIterations(5000);
	icp.setTransformationEpsilon(1e-8);
	icp.setMaxCorrespondenceDistance(1);

	pcl::PointCloud<pcl::PointXYZ> aligned_source_cloud;

	icp.align(aligned_source_cloud, initialGuess);

	if (!icp.hasConverged()) {
		std::cout << "NOT CONVERGED" << std::endl;
	}
	else {
		std::cout << "CONVERGED" << std::endl;
		std::cout << icp.getFinalTransformation() << std::endl;
	}
		
}

I have tested on PCL 1.11.1 which works as expected also in Release mode.

@LuukvandenBent LuukvandenBent added kind: bug Type of issue status: triage Labels incomplete labels Apr 16, 2024
@mvieth
Copy link
Member

mvieth commented Apr 16, 2024

Hi, deinitCompute() is used from PCLBase, which does not actually do anything. So I don't see how an exception could happen there. Could you provide a full backtrace? Also, how do you compile the code? If you use CMake, please post the CMakeLists.txt

@mvieth mvieth added module: registration and removed status: triage Labels incomplete labels Apr 16, 2024
@LuukvandenBent
Copy link
Author

I do not use Cmake, in the VS project files i've added the include directories and linked the .lib files, which I got from running the windows all-in-one installer. The backtrace is not really usefull:
image

@mvieth
Copy link
Member

mvieth commented Apr 16, 2024

@LuukvandenBent Please try using CMake then ( https://pcl.readthedocs.io/projects/tutorials/en/master/using_pcl_pcl_config.html ). There have been cases where a misconfiguration in VS led to this kind of problem (in one case a user selected debug libraries where release libraries should have been used).

@LuukvandenBent
Copy link
Author

Thank you for responding, i do not want to use CMake for this project nor should PCL be broken when not using it. It also does not make sense that an older version does work, so my guess is something got broken in the meantime.

@mvieth
Copy link
Member

mvieth commented Apr 16, 2024

@LuukvandenBent Please try building the above code with CMake nonetheless. This does not necessarily mean that you have to use CMake in your project forever. It is for now simply a way to debug the problem, that is, to rule out that a misconfiguration in VS causes the problem. Alternatively, you can wait until I have the time to build your code on Windows using CMake, but I can't say when that will be the case. My suggestion that you try CMake was simply a way find the solution faster.

@mvieth
Copy link
Member

mvieth commented Apr 18, 2024

@LuukvandenBent I tested your code on Windows with CMake, it ran fine in both debug and release configuration. One thing you can check is whether you have SSE and AVX(2) enabled for your project in Visual Studio. CMake automatically enables those as the all-in-one installer was also built with them enabled.

@LuukvandenBent
Copy link
Author

Thank you for the trouble. I do not really have the time right now to test, so if you are sure it is not something inside of PCL then i can close the issue, since using an older version is ok for now.

@mvieth
Copy link
Member

mvieth commented Apr 19, 2024

I see no evidence or reason to assume that the problem was caused by a bug in PCL. I am glad that PCL 1.11.1 works for you.

@mvieth mvieth closed this as completed Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants