• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Variable changes during method-return ?!


Hi Experts,

I have a problem with a variable that changes during the end of a method-call. I call a pointer to a method,
at the end of the method the pointer is still the same one as I passed to it, but directly after it returns, it points elsewhere :


void generateFeaturesForLocalBlock(IplImage *image, const CvRect &r, int* reducedhistogram, int redhistsize) {
         ...
      if(image!=ptr) { printf("IMAGE != PTR ...... A.6\n"); fflush(stdout); };
}


double* generateFeatures(IplImage *image, int* rval_features) {
      ...
      generateFeaturesForLocalBlock(image, r, reducedhistogram, 8);
      if(image!=ptr) { printf("IMAGE != PTR ...... 4.2\n"); fflush(stdout); };
      ...
}


The last statement in the upper method doesn't fire, while the statement after the call does. ptr is a global variable I added for debugging this.

The methods are very lengty and contain lots of debug-stuff, so I didn't post them completely. Has anyone an idea what could cause this, or where I should look at, or how I could debug this ?

The problem is, this is part of a JNI-dll, that I called from Java, which makes debugging even more difficult.

Thanks a lot !

0
dwisp
Asked:
dwisp
  • 2
  • 2
1 Solution
 
AlexFMCommented:
Some buggy code in the generateFeaturesForLocalBlock function corrupts the stack.
Try to comment off different parts of generateFeaturesForLocalBlock function to locate this code. As first step, remove all code except last line.
0
 
Infinity08Commented:
in generateFeaturesForLocalBlock, i hope you didn't change image ? Because those changes wouldn't be visible after returning ! That would be the easiest explanation, and you probably already covered that ... but I just want to make sure.

A related question : when do you set the global ptr ?

If that's not the problem, then follow AlexFM's advice ...
0
 
dwispAuthor Commented:

I'm currently evaluating AlexFM's advice. No, I do not change "image", also none of the data image is pointing to. "ptr" is being set by the first instruction in generateFeatures() :


double* generateFeatures(IplImage *image, int* rval_features) {
      ptr = image;
         ...

After that, it isn't being changed anymore (at least not explicitly).
0
 
dwispAuthor Commented:

Got it. I calculated an offset the wrong way, and wrote 32 values into an array which was of size 8. Bang.

Don't know why I haven't seen this sooner, but every time I read that piece of code it made perfectly sense to me that 256/8 = 8 ...
0
 
Infinity08Commented:
Nice !
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now