CppMT icon indicating copy to clipboard operation
CppMT copied to clipboard

Segmentation fault at 'MST_linkage_core(N,D,Z)" in Consensus.cpp

Open filipetrocadoferreira opened this issue 10 years ago • 2 comments

When I'm running the program with a VM the tracker usually crashes at that part of the code, usually when the number of active points is very low.

When I run the code in a native Ubuntu machine, usually I don't have any issue.

filipetrocadoferreira avatar Sep 28 '15 08:09 filipetrocadoferreira

I've played with this algorithm in the past, and I believe the problem you're running into has to do with the case where there is exactly one keypoint.

N,D,Z are initialized like this:

    t_index N = points.size();
    float * D = new float[N*(N-1)/2]; //This is a lot of memory, so we put it on the heap
    cluster_result Z(N-1);

But in the case where there is one keypoint, it simplifies to this:

    t_index N = 1;
    float * D = new float[0]; //This is a lot of memory, so we put it on the heap
    cluster_result Z(0);

This doesn't cause a crash on my native machine, but it would give junk data that gets thrown out since a single keypoint is treated as noise. However, I think it could cause crashes in environments where memory is more controlled, such as a VM.

Have you tried catching the case of keypoints.size() == 1 and throwing it out as early as you can? It may remove the crash.

timsee avatar Sep 29 '15 23:09 timsee

Yup, I can confirm that bailing out from consensus when number of keypoints is exactly one fixes this for me. Good find!

In fact, I believe issue #10 is just a duplicate of this one.

Will try to submit a pull request with this fix shortly.

glopesdev avatar Nov 15 '15 12:11 glopesdev