Sign in to follow this  
RanmaruX

Exact same "=" operation giving 2 different values?

Recommended Posts

What I've got: In C++ I have a Line2D class which consists of 2 points ( ev2P0 and ev2P1 )... What I'm trying to do: At one point in my code, I need make a line from the position of my enemy to a point 100 pixels above my enemy... Line2D lEnemy; lEnemy.ev2P0 = pCurrentEnemy->ev2Position; lEnemy.ev2P1 = pCurrentEnemy->ev2Position + EasyVector2D( 0.0f, 100.0f ); For some reason when I watch these values in the Visual Studio 2005 debugger, they always end up as... ev2P0 {x=300.00000 y=600.00000 } ev2P1 {x=1.0000000 y=0.00000000 } ( I expected x=300 y=700 ) I thought maybe there was something wrong with the EasyVector2D "+" operator so just as an experiment I changed the code to... Line2D lEnemy; lEnemy.ev2P0 = pCurrentEnemy->ev2Position; lEnemy.ev2P1 = pCurrentEnemy->ev2Position; and this happened... ev2P0 {x=300.00000 y=600.00000 } ev2P1 {x=1.#QNAN00 y=-1.#IND000 } ( I expected x=300 y=600 ) I am at a loss. How on earth can the same code give 2 different values? pCurrentEnemy->ev2Position is definitely not being changed. If anyone can shed any light on this, it would be greatly appreciated! PS: I tried putting my code in source tags but it made the "+" sign not show up?

Share this post


Link to post
Share on other sites
Assuming you're using the debugger correctly, it sounds like something is happening in the member access of ev2Position -- specifically, that it's getting reset. Did you try looking there?

Share this post


Link to post
Share on other sites
I just have it as a public member so I'm fairly sure there isn't anything changing that value. I just looked again though and realised it's because the debugger is foobar.

lEnemy.ev2P0 = pCurrentEnemy->ev2Position;

According to the debugger, this line is actually changing lEnemy.pNext and...

lEnemy.ev2P1 = pCurrentEnemy->ev2Position;

...is changing lEnemy.ev2P0! I get the feeling the debugger is looking at the wrong address for the members of lEnemy :(

Share this post


Link to post
Share on other sites
Clean the project, and make sure you're project settings are set up for debugging (the Debug, not Release, configuration unless you've changed the configurations).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this