# Another strange error

This topic is 2258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Why do weird errors always happen to me? Here's the latest one. Simple screenie should explain whats going wrong, and my comments below:

I'm working on heightmap-terrain. I create a new terrain in the main() function, circled at the top. I pass in 32 as the size.
In the terrain constructor, a breakpoint is hit, and inspection of the "size" argument reveals it has a value of ... whatever, it seems to change every time.

How the flying f*** can this be going wrong?

##### Share on other sites
Are you debugging an optimized build or a proper debug build? The former is not as easy and obvious to debug as the latter.

##### Share on other sites
In my experience with GDB parameters to c++ functions are not always displayed properly. If you are in debug build as BrotherBob suggests checking, I'd do a printf to confirm that it is not 32. Next thing, I'll check the address of "this" and the parameter "size" to see if for some weird reason "this" is pointing to the stack, and size is being wrongly modified, and the last thing is declaring the constructor (in the header) as
 Terrain(GraphicsDevice* graphics, uint size=32); 

and calling it (line 76 of your code) as:
 Terrain* terrain = new Terrain(graphics); 

Which should be a solution to the problem

##### Share on other sites
Visual c++ 2010, debug build.

std::cout << "Size: " << size << std::endl;

at the top of the Terrain constructor, and it is indeed 32. So why does the debugger show a nonsense number?
The "this" variable also appears to be valid, checking with the locals window

Lastly, the constructor prototype/definition are perfectly matching
So the correct value is there, but I can't see that. Which is making debugging the Render method a nightmare...

##### Share on other sites
right click on solution > clean solution
right click on solution > rebuild solution
try again

VS debugger gave me strange values a few time, doing this always fix it.

##### Share on other sites
Sometimes it is just that the compiler modifies the stack/frame pointer slightly later than expected by the debugger, and you need to execute a couple instructions into the routine to have the correct value read

• 10
• 17
• 9
• 13
• 41