I have the following struct, composed by a pointer to the next Point (nextPoint), the point's height (realHeight) and a 3D coordinate (point) from the OpenCV library, which has 3 parameters (x,y,z) :
typedef struct _cloudPoint {
    double realHeight;
    cv::Point3f point;
    _cloudPoint* nextPoint;
} cloudPoint;
And then, I need to sort a vector of cloudPoint, that I pass by pointer to a function. So i have this function's input argument:
std::vector<cloudPoint>* cPointsVector
Inside my function, I wish to sort the cPointsVector vector, using qsort, and this compare functor:
int cmp_unique(const void* _pa_, const void* _pb_) {
     Segmentation::cloudPoint* pa = (Segmentation::cloudPoint*)_pa_;
     Segmentation::cloudPoint* pb = (Segmentation::cloudPoint*)_pb_;
     if (pa->point.x > pb->point.x) {
          return -1;
     }
     else {
          if (pa->point.y > pb->point.y) {
               return -1;
          }
          else {
               if (pa->point.z > pb->point.z) {
                    return -1;
               }
          }
    }
    return 1;
}
So, to call qsort I use:
qsort(cPointsVector, cPointsVector->size(), sizeof(cloudPoint), cmp_unique);
But in the middle of the sorting process, it gives me an Segmentation fault on the functor's first if :
if (pa->point.x > pb->point.x) {
By just analysing my code, or I'm performing some incorrect memory access inside the compare functor, or the cPointsVector is being badly filled, but neither the hypotesis make sence, since I allways use non-Null cloudPoint's, with non-Null OpenCV coordinate points.
Thanks in advance
 
     
     
    