I'm having an issue while glueing together c++ vars with obj-c async code on iOS.
The real problem is located in the async code, I'm using third-party libraries built in C++ that expect object references, e.g.:
- (void) processFrame:(cv::Mat &)mat;
My problem real problem is how to call this ? I need to create the c++ object on a different thread and pass it to the async code, a bit like this:
__block cv::Mat mat(videoRect.size.height, videoRect.size.width, CV_8UC4, baseaddress, 0);
dispatch_async(dispatch_get_main_queue(), ^{
[self processFrame:mat];
});
Which give an error (Bad access), the problem is (I guess) the object is destroyed before the method runs, so I tried creating the object in the heap:
__block cv::Mat *mat= new cv::Mat(videoRect.size.height, videoRect.size.width, CV_8UC4, baseaddress, 0);
dispatch_async(dispatch_get_main_queue(), ^{
[self processFrame:(*mat)];
});
And still:
__block cv::Mat *mat= new cv::Mat(videoRect.size.height, videoRect.size.width, CV_8UC4, baseaddress, 0);
dispatch_async(dispatch_get_main_queue(), ^{
[self processFrame:mat];
});
I get keeping "Bad access" errors all the time
Any ideas ?