我試圖找到導致我的程序崩潰的原因。執行幾個小時後程序崩潰
這個崩潰發生在幾個小時的執行後。我使用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除。事實上,您總是增加'nTimesAlive'並不排除它在溢出時達到0 ...或者,查找您可能正在修改內存的內存訪問問題其中nTimesAlive是通過錯誤的指針或緩衝區溢出 – jsantander
如果你在gdb中有它,你可以打印所涉及的變量/參數......例如:確保'itCand'是理智的。確保(* itCand) - > _ sumAreaMask和(* itCand) - > _ nTimesAlive的值... – jsantander
感謝您指出nTimesAlive,它是未簽名的,因此它只會運行~65000幀,直到它溢出。這是問題。 –