Ask Your Question

Why is this triggering EXC_BAD_ACCESS?

asked 2014-07-17 15:17:28 -0500

aledalgrande gravatar image

updated 2014-07-17 15:45:01 -0500

Sometimes this code triggers a critical error. I tried to put every condition I could think of to prevent bad input, but it's still not working sometimes.

- (Vec3f)extractColorWithKeyframe:(Keyframe*)keyframe WithPosition:(Point2f)position
    Mat image = keyframe.originalImage;
    if (image.rows < 1 || image.cols < 1 || ![ isInFrame:position withBoundary:0] || image.channels() < 4)
        return Vec3f(0,0,0);

    Vec4b bgra;
    bgra =<Vec4b>(position.x, position.y);

Any clue?

edit retag flag offensive close merge delete


weird language: ![ isInFrame:position withBoundary:0]

please clarify / add a resp. language tag (and please without any # shit).

berak gravatar imageberak ( 2014-07-17 15:22:46 -0500 )edit

Ah that is Objective C. It's just a check to see if position is inside the image.

aledalgrande gravatar imagealedalgrande ( 2014-07-17 15:34:42 -0500 )edit

Added the beginning of the method as well.

aledalgrande gravatar imagealedalgrande ( 2014-07-17 15:36:45 -0500 )edit

PS: I was using the hashtags because they come up first in the auto-complete

aledalgrande gravatar imagealedalgrande ( 2014-07-17 15:45:27 -0500 )edit

yea, not your fault. known limitation/problem with the site in general.

(though a great litmus test to see, who cares...)

berak gravatar imageberak ( 2014-07-17 15:49:57 -0500 )edit

hey, again, apologies for sounding somewhat grumpy, you don't deserve it.

berak gravatar imageberak ( 2014-07-17 15:52:12 -0500 )edit

I solved it, had a stupid variable shadowing in an upper for loop that was passing a null reference for the position in this method, so it would "seem" valid to the compiler, but at runtime it would crash. No worries, everybody has a bad day, but keep contributing to the OpenCV community!

aledalgrande gravatar imagealedalgrande ( 2014-07-17 15:59:27 -0500 )edit

you might be able to answer your own question now...

berak gravatar imageberak ( 2014-07-17 16:04:26 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-17 16:30:26 -0500

aledalgrande gravatar image

The error was in how I passed the value to position, which is a Point2f type. In this case it was a memory leak, but in XCode it would show as a Point2f variable with empty values for x and y, not as a null value. That's what was confusing.

Always check for a valid value, in this case when a Point2f variable is initialized, it is set to Point2f(0,0) by the constructor.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-07-17 15:17:28 -0500

Seen: 446 times

Last updated: Jul 17 '14