Sorry, this content is no longer available

Ask Your Question
1

Why is this triggering EXC_BAD_ACCESS?

asked Jul 17 '14

aledalgrande gravatar image

updated Jul 17 '14

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 || ![keyframe.camera isInFrame:position withBoundary:0] || image.channels() < 4)
        return Vec3f(0,0,0);

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

Any clue?

Preview: (hide)

Comments

weird language: ![keyframe.camera isInFrame:position withBoundary:0]

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

berak gravatar imageberak (Jul 17 '14)edit

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

aledalgrande gravatar imagealedalgrande (Jul 17 '14)edit

Added the beginning of the method as well.

aledalgrande gravatar imagealedalgrande (Jul 17 '14)edit

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

aledalgrande gravatar imagealedalgrande (Jul 17 '14)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 (Jul 17 '14)edit

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

berak gravatar imageberak (Jul 17 '14)edit
1

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 (Jul 17 '14)edit

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

berak gravatar imageberak (Jul 17 '14)edit

1 answer

Sort by » oldest newest most voted
0

answered Jul 17 '14

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.

Preview: (hide)

Question Tools

Stats

Asked: Jul 17 '14

Seen: 901 times

Last updated: Jul 17 '14