Ask Your Question
1

Bad pointer issue in c++

asked 2012-09-24 09:08:31 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hi All,

I had a problem. Basically, was little strange. I have a feeling it might be a bug in OpenCV. But not sure. The below code works only in debug mode but not in release mode (VS 2010 express edition). The problem is string variable path shows bad pointer and doesn’t assign the value as given below to it. I am using OpenCv 2.4.0.

cv::Mat testMatrix(3,3,CV_64F);
std::string path = ".\\input";
std::cout<<path ;

If I remove the first line it works fine. And this problem occurs only in release mode not in debug mode. Do you have any suggestions ?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2012-09-24 12:17:39 -0600

updated 2012-09-24 12:39:59 -0600

Strange errors like the one you mentioned may happen, when linking against the wrong libraries. A lot of people had this problem, when linking against the OpenCV libraries without Debug Symbols in the Debug mode. See if you link against the correct libraries and let me know if it fixes your problem.

For more information see:

Here is an example for OpenCV 2.3.1, probably you encounter something similar:

edit flag offensive delete link more

Comments

Thanks a lot...Your solution was helpful. Now I dont have the bad pointer issue.

Subhasis gravatar imageSubhasis ( 2012-09-25 15:11:40 -0600 )edit
0

answered 2012-09-24 09:43:30 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Suggest you do a "Rebuild Solution" and see if the problem persists.

edit flag offensive delete link more

Comments

I tried to rebuild the solution with no success. If i try to put the string variable global it doesnt have any problem. But inside the same function they create problem (only in the release mode). I really am unable to figure out the reason.

Subhasis gravatar imageSubhasis ( 2012-09-24 10:24:50 -0600 )edit

There is definitely a pointer that is overwriting the location allocated to another pointer. I had it happen once when I accidentally shot past a pointer. My code took me to foobar[3] when the array was allocated as foobar[3]. I had used some in-house tools to dump core at that time to analyze the situation. Possibly, you can inspect the code with some tool to get the same information.

unxnut gravatar imageunxnut ( 2012-09-24 11:39:29 -0600 )edit

Hi, I completely agree with your point about the pointer getting overwritten.As you see there are only 3 lines of code in the program and no other variable. The only thing I am unable figure out in these 3 lines of code, where exactly it occurs. If I remove the first line of the cv::mat object i dont get the bad pointer problem in release mode as well. I would really appreciate if you can give me a hint of where can this behaviour occur regarding the illegal memory overwritting

Subhasis gravatar imageSubhasis ( 2012-09-24 11:57:16 -0600 )edit

Question Tools

Stats

Asked: 2012-09-24 09:08:31 -0600

Seen: 1,133 times

Last updated: Sep 24 '12