nanoflann
nanoflann copied to clipboard
Segment fault caused by weird ret_matches.first the point index
Hi,
When I put code like this (declare ret_matches and params inside the for loop):
for (size_t i = 0; i < num_pts; ++i) {
const double query_pt[3] = {cloud->pts[i].x, cloud->pts[i].y, cloud->pts[i].z};
std::vector<std::pair<size_t, double> > ret_matches;
nanoflann::SearchParams params;
params.sorted = false;
const size_t num_matches = index.radiusSearch(&query_pt[0], radius, ret_matches, params);
...
}
I got a weird ret_matches for a specific query_pt[3] see below idx[6] which cause my subsequent code segfault:
query_pt(): x=1.60208 y= 0.486532 z= 13.0649
radiusSearch(): radius=0.6 -> 13 matches
idx[0]=14279 dist[0]=0.501927
radiusSearch(): radius=0.6 -> 13 matches
idx[1]=14204 dist[1]=0.469623
radiusSearch(): radius=0.6 -> 13 matches
idx[2]=14154 dist[2]=0.0159013
radiusSearch(): radius=0.6 -> 13 matches
idx[3]=14208 dist[3]=0.501593
radiusSearch(): radius=0.6 -> 13 matches
idx[4]=14159 dist[4]=0
radiusSearch(): radius=0.6 -> 13 matches
idx[5]=12428 dist[5]=0
radiusSearch(): radius=0.6 -> 13 matches
**idx[6]=9218868437227405311** dist[6]=2.22507e-308
I don't know how to solve this problem because queries of all previous points seems working perfect. And even I take this specific point out and query this single point (query_pt(): x=1.60208 y= 0.486532 z= 13.0649) it is working perfect also. So I guess this is not the query problem of specific point. Finally I solve this problem in a way up till now I don't know why: Take ret_matches and param definition out of the for loop like bellow. Now it works perfectly. Any one could tell me why? I am using nanoflann-1.2.1 version on Ubuntu14.04 64bit.
std::vector< std::pair<size_t, double> > ret_matches;
nanoflann::SearchParams params;
params.sorted = false;
for (size_t i = 0; i < num_pts; ++i) {
const double query_pt[3] = {cloud->pts[i].x, cloud->pts[i].y, cloud->pts[i].z};
const size_t num_matches = index.radiusSearch(&query_pt[0], radius, ret_matches, params);
...
}