Ask Your Question
1

Why is this triggering EXC_BAD_ACCESS?

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

aledalgrande gravatar image

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

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?

edit retag flag offensive close merge delete

Comments

weird language: ![keyframe.camera 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 -0600 )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 -0600 )edit

Added the beginning of the method as well.

aledalgrande gravatar imagealedalgrande ( 2014-07-17 15:36:45 -0600 )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 -0600 )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 -0600 )edit

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

berak gravatar imageberak ( 2014-07-17 15:52:12 -0600 )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 ( 2014-07-17 15:59:27 -0600 )edit

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

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

1 answer

Sort by ยป oldest newest most voted
0

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

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

Question Tools

Stats

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

Seen: 885 times

Last updated: Jul 17 '14