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 Plotter crashes with vector of same value #1124

Closed
hacke1978 opened this issue Jan 29, 2015 · 1 comment · Fixed by #1126
Closed

PCL Plotter crashes with vector of same value #1124

hacke1978 opened this issue Jan 29, 2015 · 1 comment · Fixed by #1126

Comments

@hacke1978
Copy link

Hello

I make intensity value histograms inside my UI. Some clouds have an artificial value of 120 for every point, so the vector I pass to the plotter contains only 120. This crashes my program. I make a workaround and add 0 and 255 (one is enough), which doesnt has a visible effect to the plot. But comment the lines out where I add those values and it will crash. Most likely this wont happen to many users, as in natural data this will never happen...

#include <iostream>
#include<pcl/visualization/pcl_plotter.h>

int
main ( int argc, char** argv ) {

    pcl::visualization::PCLPlotter * plotter = new  pcl::visualization::PCLPlotter;
    std::vector
    <double> data_vec;
    for(int i = 0; i < 1000; ++i)
    {
      data_vec.push_back(120);
    }

    data_vec.push_back(0);
    data_vec.push_back(255);
    plotter->addHistogramData ( data_vec, 256 );          
    plotter->spin();                                    
}
@VictorLamoine
Copy link
Contributor

The problem is very simple to solve; if you want to learn how to fix things in PCL this is the perfect opportunity.

1. Use a debugger to find where the program crashes

Follow this tutorial and debug your program. The PCL version you are linking to must have been compiled in Debug mode. You also need to set CMAKE_BUILD_TYPE to Debug

cmake -G "Eclipse CDT4 - Unix Makefiles" ../src -DCMAKE_BUILD_TYPE=Debug

Open the project with eclipse and launch the debugging, you should be able to go step by step in the program. Learn how to use breakpoints!

2. Determine why it crashes

The program crashes in pcl::visualization::PCLPlotter::computeHistogram,

  double size = (max - min) / nbins;

With min == max; size = 0.

At this line, we try to divide by zero

unsigned int index = (unsigned int) (floor ((data[i] - min) / size));

3. Fix the problem

double size = (max - min) / nbins;
if (size == 0) size = 1.0;

Test and make a pull request when everything works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants