我试图找到导致我的程序崩溃问题的原因。
此崩溃发生在执行几个小时后。我使用gdb运行它,它告诉我它崩溃了哪行代码。 Gdb告诉我该程序在以下行中有一个浮点exeption segfault :
(*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 :(得分:1)
看起来问题发生在控件到达函数体之前。所以我认为最可能的错误来源是以下几行:
(*itCand)->_sumAreaMask / (*itCand)->_nTimesAlive,
(*itCand)->_sumAreaEdges / (*itCand)->_nTimesAlive,
(*itCand)->_sumHeight / (*itCand)->_nTimesAlive ,
使用GDB,您可以检查指向itCand的指针是否有效,以及异常发生时_nTimesAlive的值是多少。您还可以尝试在函数调用之前声明3个临时变量以保存这3个计算结果,然后将它们传递给函数。因此,您将使GDB报告导致问题的确切行并收集有关故障的更多详细信息。