Hi,
I have the following method and I would like to know why this makes my program to crash?
I come from an Objective-C background where nothing occurs when an instance that is NULL or zero is sent a method.
As you can see, when there is no blobs to iterate in the list the method will return NULL and my program just crashes.Code:blob LLAHTracking::ClosestBlobToPoint2D(CvPoint point){ int minDist = 999999; int dist; blob *closestBlob = NULL; MyBlobList::blobs *blobs = m_bloblist.ExtractedBlobs(); for(MyBlobList::blobs::iterator iblob = (*blobs).begin(); iblob != (*blobs).end(); iblob++){ dist = (*iblob)->distance(point.x, point.y); if( dist < minDist ){ minDist = dist; closestBlob = (*iblob); } } return *closestBlob; }
How can I solve this kind of errors? Or maybe is any other reason I might be missing?
Thanks in Advance