2014-04-04 46 views
0

我試圖找到導致我的程序崩潰的原因。執行幾個小時後程序崩潰

這個崩潰發生在幾個小時的執行後。我使用gdb運行它,它告訴我它在哪一行代碼崩潰。 GDB告訴我,該方案具有浮點exeption段錯誤上下面的行:

(*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); 

此功能的數據分配給一個對象。參數sumAreaFilled,sumAreaEdges和height是增量參數,每秒執行一次,因此它們的類型爲unsigned long long,以避免任何內存問題。

參數nTimesAlive初始化爲1,並且每幀都保持遞增,所以它永遠不會爲零。

其餘的操作都是簡單的任務,所以我認爲他們不是任何問題的根源,但我會粘貼函數和數據類型,以便掌握必要的所有信息來掌握問題。

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; 
}; 

而且功能:

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; 
} 
+0

浮點異常很可能是被0除。事實上,您總是增加'nTimesAlive'並不排除它在溢出時達到0 ...或者,查找您可能正在修改內存的內存訪問問題其中nTimesAlive是通過錯誤的指針或緩衝區溢出 – jsantander

+1

如果你在gdb中有它,你可以打印所涉及的變量/參數......例如:確保'itCand'是理智的。確保(* itCand) - > _ sumAreaMask和(* itCand) - > _ nTimesAlive的值... – jsantander

+0

感謝您指出nTimesAlive,它是未簽名的,因此它只會運行~65000幀,直到它溢出。這是問題。 –

回答

1

它看起來像控制到達函數體之前發生的問題。所以,我認爲錯誤的最可能的來源是以下行中:

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

隨着GDB可以檢查指針itCand是否有效,什麼是_nTimesAlive在發生異常時的值。您也可以嘗試在函數調用之前聲明3個臨時變量以保存這3個計算結果,然後將它們傳遞給該函數。因此,您將使GDB報告導致問題的確切線路並收集有關故障的更多詳細信息。

+0

我將nTimesAlive聲明爲unsigned short,所以它只會在ir到達第65000幀時正常運行。 –