Reputation: 316
Alright guys, after my last question I did some more work on the app. Again I have two viewports that show two different point clouds. The current selected point in a viewport is highlighted using a white color. I'll put a picture here for better understanding:
Using the Enter-Key, I can store two points (one per viewport) in two point clouds called storedCloudLeft
and storedCloudRight
. These points are correspondences for a registration. So the user selects one point in the left viewport and it will be stored in storedCloudLeft
. The same thing for the right one.
If the points are stored, they will be shown using a red color. See this picture:
So, let's say the user made a mistake while setting these points and wants to remove the last point pair in the point clouds. The user can do that using the BackSpace-Key. This will call the following function:
void resetStoredPointClouds(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud, std::string cloud_id) {
// Remove the last point
cloud->erase(cloud->end() - 1);
// Update the point clouds using a red color
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> red(cloud, 235, 19, 19);
viewer->updatePointCloud(cloud, red, cloud_id);
}
So if there are two point pairs (which means in storedCloudLeft
and storedCloudRight
two points are stored), I just can remove the points by calling the above function for each cloud and it all works. But if there are more than two points stored per point cloud (that means three or more), some real weird problems show up.
If some of these points were deleted so only two points per cloud remain and the user hits BackSpace to remove this pair, the program crashes with the following error message:
terminate called after throwing an instance of 'std::length_error'
what(): vector::reserve
Afaik I never call the reserve
-function. And a length_error for reserve
is usually thrown out if the user tries to reserve so much indices for a vector that it's max size is exceeded.
So, at first I thought the source for this error message was a bad handling of deleting the points. But using this tutorial delivered the same error. So I tried to debug the whole thing. And now comes the weirdest part: This error doesn't even occur when the above code is run. It comes in the main
-function after
viewer->spinOnce (100);
has run for some time. And after some more experimenting, I found out that the error message is not shown when the updatePointCloud
-command is not executed. But if I go through this step in the debugger, no error is shown.
This is confusing in so many ways. What does a length error have to do with an updatePointCloud
-Statement? Why is this error not thrown using the debugger? Why does it happen only if I have three or more points stored in the cloud? What am I doing wrong? I have a feeling that I messed something up completely and I just don't find the corresponding part.
Does anybody have an idea what to do and how to fix this? Or is this a known bug? Is it even a good way to use this function? Any help would be greatly appreciated!
Bakefish
Upvotes: 1
Views: 629
Reputation: 316
Okay, so I did some more research and I am pretty sure that the reason for this error is a bug inside the updatePointCloud
method. There is already a github issue under this link.
No idea how exactly this error happens, but fortunately, there is a workaround for this problem.
So in case another one has this problem, replace the uodatePointCloud
with the functions removePointCloud
and then addPointCloud
for the corresponding cloud. Regarding performance, it's slower than just updating, but for now it should do the trick.
The issue has been verified... hope they will fix it soon.
EDIT: PCL 1.11 is now relased, this issue was fixed with that version.
Upvotes: 2