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

Usage of updatePointCloud leads to length_error in vector::reserve #4001

Closed
MaxFleur opened this issue Apr 30, 2020 · 10 comments
Closed

Usage of updatePointCloud leads to length_error in vector::reserve #4001

MaxFleur opened this issue Apr 30, 2020 · 10 comments
Labels
kind: bug Type of issue module: visualization needs: author reply Specify why not closed/merged yet

Comments

@MaxFleur
Copy link

MaxFleur commented Apr 30, 2020

Description
When using the viewer function updatePointCloud a length_error in vector::reserve is thrown out.

Context

I want to delete points out of a point cloud. To do that, I created a KeyEvent function that deletes the points using the BackSpace key.
The code to delete the newest point (which means the last index inside the point cloud) and update the cloud goes as follows:
if(event.getKeySym () == "BackSpace" && event.keyDown()) {
if(!cloud.empty) {
// delete the "newest" point in the point cloud.
cloud->erase(cloud->end() - 1);
// Use any color you like to visualize the cloud
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> red(cloud, 235, 19, 19);
m_viewer->updatePointCloud(cloud, red, "cloud");
}
}

Expected behavior

The user should be able to delete all points of the cloud until no points remain.

Current Behavior

If the point cloud contains more than three points and points are deleted until only two points remain, the following issue will be displayed if the user wants to delete a point again:
terminate called after throwing an instance of 'std::length_error' what(): vector::reserve
This error is only thrown if the function updatePointCloud is used. But if the function is used this error will be thrown while running the function viewer->spinOnce(100);

To Reproduce

  1. Create a basic pcl project and create a random point cloud with at least three points.
  2. Add a KeyEvent function using an arbitrary key to delete points using the function as mentioned above.
  3. Delete the points until only two points remain.
  4. Hit the arbitrary key again.

-> Now this error occures.
-> At first, I thought this issue might be caused due to the
cloud->erase(cloud->end() - 1);
because I thought it might be some bad code. But this is definitely not the issue. I tried to delete points using an ExtractIndices-function (as mentioned here and the error occured nonetheless.
-> If the point cloud contains only two points, everything works fine, so no error is displayed. It only happens if the cloud contains three or more points.
-> I already created a stackoverflow entry for this issue (see here) but there is now answer until now.

-> I have a picture of the full stacktrace after the error was thrown. I'll put it here:
stacktrace

Tested environment

  • OS: ManjaroLinux 20.0
  • Compiler: GCC 9.3.0
  • PCL Version: 1.10

Let me know if you need some more information. Cheers!

@MaxFleur MaxFleur added kind: bug Type of issue status: triage Labels incomplete labels Apr 30, 2020
@MaxFleur MaxFleur changed the title [module_name] Usage of updatePointCloud leads to length_error in vector::reserve Usage of updatePointCloud leads to length_error in vector::reserve Apr 30, 2020
@kunaltyagi
Copy link
Member

kunaltyagi commented Apr 30, 2020

This is not a MCVE. Seems unrelated to PCL based on information provided

Also the erase call looks suspiciously bad. Try if (!vector.empty()) vec.erase(vec.crbegin());

@kunaltyagi kunaltyagi added module: visualization needs: author reply Specify why not closed/merged yet and removed status: triage Labels incomplete labels Apr 30, 2020
@MaxFleur
Copy link
Author

MaxFleur commented Apr 30, 2020

This is not a MCVE. Seems unrelated to PCL based on information provided

Are there some more informations needed? I pointed out that this issue is related to updatePointCloud.

Also the erase call looks suspiciously bad. Try if (!vector.empty()) vec.erase(vec.crbegin());

The erase call was used due to an administrator post from here. Also it's not possible to call crbegin(). It's only possible to do that for the points vector within the cloud. Is that what you mean?

@kunaltyagi
Copy link
Member

kunaltyagi commented Apr 30, 2020

I didn't notice you were using the cloud. The usage appears correct, except at size() = 0

Regarding MCVE, you example isn't minimum or easily verifiable. The issue also doesn't show that the problem is in the library or some code you wrote (in which case SO is the best place)

@MaxFleur
Copy link
Author

Alright, I did some more testing and stripped down the issue. Hope it's more clear now.

@kunaltyagi
Copy link
Member

Delete the points until only two points remain

Possible issue: user-code: The delete then tries to delete 2 or 3 poins, trying to delete position -1

Closing in favor of the SO question since issue seems unrelated to PCL library code.

@MaxFleur
Copy link
Author

The delete only deletes one point per function call and it is always the last point. This does work if the cloud only contains two points at the beginning. All ppints can be deleted. I've pointed that out- Also, I wrote that this problem occurs as well if an ExtractIndices-Function was used and that this issue only occures if the updatePointCloud-function is executed.
Therefore, I don't really understand why this issue is closed now. :-\

@kunaltyagi
Copy link
Member

  • There is an issue in PCL updatePointCloud which appears if the new point cloud is larger than the older. This isn't the case here. You can try using removePointCloud + addPointCloud instead of update, but based on discussions, it will not help you.
  • The other place where it could be PCL's fault is in erase function. But the check for empty (seems wrong to use variable instead of a function-call) implies that can't be the reason.
  • No other avenue is available because what you've provided isn't a MCVE. An MCVE is a self sustained piece of code

The last is the key point. Without that, based on first 2 points, I can't be sure that the issue isn't in user-code.

@MaxFleur
Copy link
Author

MaxFleur commented May 1, 2020

Okay, I understand. Will remember it the next time. :-)
I found another issue on this page about this (listed here).
So I tried it using the removePointCloud + addPointCloud as you and the other users suggested. Frankly, that did it. It works for now. Thank you!

Should I create an MCVE nonetheless? I can provide a minimal example of code to give some more details, but the issue is already there so I'm not sure whether that's really necessary.

@SergioRAgostinho
Copy link
Member

If you don't mind that would be great. It would save me some time setting up things ourselves and we could jump straight into debugging the issue 😬

@MaxFleur
Copy link
Author

MaxFleur commented May 1, 2020

Alright, I've put a very small project together to reproduce this issue. Here you go:
LengthError.zip

larshg added a commit to larshg/pcl that referenced this issue May 2, 2020
larshg added a commit to larshg/pcl that referenced this issue May 8, 2020
kunaltyagi added a commit that referenced this issue May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Type of issue module: visualization needs: author reply Specify why not closed/merged yet
Projects
None yet
Development

No branches or pull requests

3 participants