Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

exc_bad_access when using Mat in OpenCV although it looks like my indexes are correct

I develop some algorithm on Mac using Xcode 5 and OpenCV. I do it as C++.

I define matrix:

Mat src;
int cols = 560;
int rows = 260;
src.create( rows, cols, DataType<double>::type);

In the code I have a loop looks like this:

for (int i=0; i<src.rows; i++) {
        const double* srcIterator = src.ptr<double>(i);
        for (int j=0; j<src.cols; j++) {
            double temp = srcIterator[j];
            temp++;
        }
    }

I read the function that has this loop for every frame I read. Most of the times it runs correctly (it is running in endless loop and it always ok).

In some runs I get exc_bad_access error. When it happened it happened for the first frame. The error is on the line: double temp = srcIterator[j];

When it happened j is much bellow 560 and alway above 500, but each time it has a deferent value.

I thought may be I mix the cols and rows but if it was right I would get this error when j was 260 (the size of rows).

Please, Anyone has any guess what can it be?