0

I'm trying to find the cause of a crashing problem I'm having on my program.

This crash happens after some hours of execution. I ran it using gdb, which tells me in which line of code it crashed. Gdb tells me that the program has a floating point exeption segfault on the following line:

(*itCand)->setCandidateObjectData(centroid,
                                    (*itCand)->_toSendCentroid,
                                    bbox,
                                    sumAreaFilled,
                                    sumAreaEdges,
                                    height ,
                                    (*itCand)->_sumAreaMask / (*itCand)->_nTimesAlive,
                                    (*itCand)->_sumAreaEdges / (*itCand)->_nTimesAlive,
                                    (*itCand)->_sumHeight / (*itCand)->_nTimesAlive ,
                                    sumAreaEdges,
                                    height,
                                    maxHeight,
                                    false,
                                    false,
                                    false,
                                    true,
                                    hasChangedPosition);

This function assigns data to an object. The parameters sumAreaFilled, sumAreaEdges and height are incremental parameters that keep increasing every second of the execution, and for that reason they are of type unsigned long long, to avoid any memory issues.

The parameter nTimesAlive is initialized as 1, and keeps incrementing every frame aswell, so it can never be zero.

the rest of the operations are simple assignments, so I am thinking they are not the source of any issue, but I'll paste the function and the data type so that you can all the information necessary to grasp the problem.

class CandidateObject
{
public:
    CandidateObject(const cv::Point centroid, const cv::Rect bboxNormal);

    ~CandidateObject();

    void setCandidateObjectData(const cv::Point centroid, const cv::Point toSendCentroid, const cv::Rect bboxNormal,
            const unsigned long long sumAreaMask, const unsigned long long sumAreaEdges, const unsigned long long sumHeight,
            const double meanAreaMask, const double meanAreaEdges, const double meanHeight, const double instantEdgeArea, const double height,
            const double maxHeight, const bool isToDelete, const bool isDuplicate, const bool isBeingDoubleChecked, const bool isMatched,
            const bool hasChangedPosition);

    cv::Point _centroid;                //-- blob centroid
    cv::Point _toSendCentroid;          //-- blob centroid to send to the conversion function
    cv::Rect _bboxNormal;               //-- normal bounding box
    unsigned long long _sumAreaMask;    //-- pixel sum on object bounding box mask
    unsigned long long _sumAreaEdges;   //-- pixel sum on edge
    unsigned long long _sumHeight;      //-- sum of height instances
    double _meanAreaMask;               //-- mean of total instances of object area in bounding box mask
    double _meanEdgeAreaMask;           //-- mean of total instances of object area in the edge bounding box mask
    double _meanHeight;                 //-- mean of total instances of object height
    double _instantEdgeArea;            //-- Area of edges that correspond to a certain object
    unsigned short _nTimesAlive;        //-- number of times blob appears
    bool _isToDelete;                   //-- flag that indicates if candidate object is no longer valid and to be deleted from vector
    bool _isDuplicate;                  //-- indicates if same object is detected multiple times
    bool _isBeingDoubleChecked;         //-- indicates if object is being double checked after first matching fails
    bool _isMatched;                    //-- indicates if object has already been matched, in order to avoid unnecessary processing
    bool _hasChangedPosition;           //-- indicates if the object has changed its position significantly
    double _height;                     //-- object height
    double _maxHeight;                  //-- max height
    unsigned int _label;
};

And the function:

void CandidateObject::setCandidateObjectData(const cv::Point centroid, const cv::Point toSendCentroid, const cv::Rect bboxNormal,
        const unsigned long long sumAreaMask, const unsigned long long sumAreaEdges, const unsigned long long sumHeight,
        const double meanAreaMask, const double meanAreaEdges, const double meanHeight, const double instantEdgeArea, const double height,
        const double maxHeight, const bool isToDelete, const bool isDuplicate, const bool isBeingDoubleChecked, const bool isMatched, const bool hasChangedPosition)
{
    _centroid = centroid;
    _toSendCentroid = toSendCentroid;
    _bboxNormal = bboxNormal;
    _sumAreaMask += sumAreaMask;
    _sumAreaEdges += sumAreaEdges;
    _sumHeight += sumHeight;
    _meanAreaMask = meanAreaMask;
    _meanEdgeAreaMask = meanAreaEdges;
    _meanHeight = meanHeight;
    _instantEdgeArea = instantEdgeArea;
    _isToDelete = isToDelete;
    _isDuplicate = isDuplicate;
    _isBeingDoubleChecked = isBeingDoubleChecked;
    _isMatched = isMatched;
    _height = height;
    _maxHeight = maxHeight;
    _hasChangedPosition = hasChangedPosition;

    return;
}
Pedro Batista
  • 1,100
  • 1
  • 13
  • 25
  • Floating point exception is likely to be a division by 0. The fact that you always increase `nTimesAlive` does not preclude it reaching 0 when it overflows... Alternatively, look for memory access problems where you might be modifying the memory where nTimesAlive is through a wrong pointer or buffer overflow – jsantander Apr 04 '14 at 09:49
  • 1
    If you have it within gdb, you can print the variables/parameters involved... for example: make sure that `itCand` is sane. Make sure of the values of (*itCand)->_sumAreaMask and (*itCand)->_nTimesAlive... – jsantander Apr 04 '14 at 09:51
  • thanks for pointing out to nTimesAlive, it is unigned short so it will only run for ~65000 frames, until it overflows. Thats the issue. – Pedro Batista Apr 04 '14 at 10:04

1 Answers1

1

It looks like the problem occurs before the control reaches the function body. So I think the most probable source of the error is within the following lines:

(*itCand)->_sumAreaMask / (*itCand)->_nTimesAlive,
(*itCand)->_sumAreaEdges / (*itCand)->_nTimesAlive,
(*itCand)->_sumHeight / (*itCand)->_nTimesAlive ,

With GDB you can inspect whether the pointer to itCand is valid, and what is the value of _nTimesAlive at the time the exception occurs. You can also try to declare 3 temporary variables right before the function call to hold these 3 calculation results, and then pass them to the function. Thus you will make GDB to report the exact line which causes the problem and collect more details about the fault.

Uniqus
  • 564
  • 1
  • 5
  • 21