Help:
It crashes on the device. It crashes in the simulator. But it won't crash in Instruments tool. I admit, I am still learning how to use the Instruments tool and perhaps am not setting the correct settings to catch the error. But I've been working for days on this and it is driving me crazy. All of my code appears to be executing perfectly fine. I am using NSNotificationCenter for callbacks. The data is there when execution returns to the view and the data is getting set in my code. The problem occurs when the view is about to display the new data. Instead, the view disappears and the app crashes due to a EXC_BAD_ACCESS error. I am completely stumped.
I'm confused about how NSZombie works with the Instruments tool. Some instructions say you cannot use NSZombiesEnabled with the Instruments tool. I have not been able to successfully look at the logs either. Perhaps I'm trying to look at the wrong logs, because the logs I looked at didn't appear to be in human readable format.
I am almost 99.9% convinced that the problem began when we started (in C++) converting CVMat bitmaps to gray scale for processing, processing the image in C++, and then converting back to color in C++ for displaying. But even putting a try/catch block around it did not catch the error. The callback in Objective-C receives a UIImage.
Asynchronous calls, multiple languages, wrappers, OpenCV library, lots of points of failure. I believe that it is imperative that I become an expert with the Instruments tool for many reasons, but right now I'm desperate for any advice I can get.
I am going through the Ray Wenderlich tutorial right now, but appreciative of information from others who may have experienced a similar problem.
What I was really hoping to find is that someone else had this error somewhere in the Assembly code after their code processing was complete, as was happening to me. I couldn't put any breakpoints, because it didn't appear to be happening in my code. But after a lot of patience and a few extra eyes, I was finally able to find the root cause.
It was an OpenCV issue!!! I narrowed the error down to the method where the error was occurring (not really easy since it wasn't stopping on that call) but after splitting the cvMatFromUIImage method into two methods (one to convert the image into a cv::Mat and the other to change the color) the error went away.
- (cv::Mat)cvMatFromUIImage:(UIImage *)image
{
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
CGFloat cols = image.size.width;
CGFloat rows = image.size.height;
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels (color channels + alpha)
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data
cols, // Width of bitmap
rows, // Height of bitmap
8, // Bits per component
cvMat.step[0], // Bytes per row
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
CGContextRelease(contextRef);
return cvMat;
}
- (cv::Mat)convertToRGB:(cv::Mat)grayMat
{
cv::Mat rgbMat;
cv::cvtColor(grayMat, rgbMat, CV_RGBA2RGB);
return rgbMat;
}
I hope this helps somebody else!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With