Archived

This topic is now archived and is closed to further replies.

FlamePixel

Impossible Value Change!

Recommended Posts

Here is the source to two functions in my cMouse class... Ttwo private member variables (m_X and m_Y) seem to magically change values! Note that I call no methods of cMouse in between the constructor and Draw. This is baffling me! Here''s the source:
cMouse::cMouse(sDX* pDX)
{
  m_pDX = pDX;

  if(FAILED(D3DXCreateTextureFromFileEx(m_pDX->m_pD3DDevice, "Data/Mouse.tga", D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, D3DCOLOR_ARGB(0,255,255,255), NULL, NULL, &m_Texture)))
    m_Texture = NULL;

  log("About to Init Coords");
  m_X = 0;
  m_Y = 0;
  log("Just Initiated Coords... Here they are:");
  log((int)m_X);
  log((int)m_Y);

  return;
}



void cMouse::Draw(void)
{
  log("Here they are, ready to draw:");
  log((int)m_X);
  log((int)m_Y);
  
  if (FAILED(m_pDX->m_Mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&m_MouseState)))
    return;
      
  if(m_MouseState.lX != 0) m_X += m_MouseState.lX;
  if(m_MouseState.lY != 0) m_Y += m_MouseState.lY;  

  if(m_Texture == NULL) return;
 
  D3DXVECTOR2 translation;
  translation.x = m_X;
  translation.y = m_Y;

  m_pDX->m_pSprite->Draw(m_Texture, NULL, NULL, NULL, 0, &translation, 0xffffffff);
  
  return;
}
log is a function that simply writes data to a log. Here''s the log file after a few frames of runtime. Note that the coords update the way they are supposed to, they just start out with a wacky Y coord.
About to Init Coords
Just Initiated Coords... Here they are:
0
0
Here they are, ready to draw:
0
524288
Here they are, ready to draw:
0
524288
Here they are, ready to draw:
0
524288
Here they are, ready to draw:
0
524287
Here they are, ready to draw:
1
524270
Here they are, ready to draw:
1
524270
Here they are, ready to draw:
1
524270

Share this post


Link to post
Share on other sites
What happens outside of debug mode? Sometimes I find that the compiler is at fault, so I simply delete all the files and have MSVC recompile everything.

Share this post


Link to post
Share on other sites
The easiest way to do it is to step through the debugger, and always monitor those variables, then you can see when they get modified. And if they aren''t already, make sure they''re private variables. Remember though that if you''re debugging it, make sure you can access them globally, or else its kinda useless, so add a function to your class that returns them.


Also, this is is redundant:
if(m_MouseState.lX != 0) m_X += m_MouseState.lX;
if(m_MouseState.lY != 0) m_Y += m_MouseState.lY;

Instead, it can just be:
m_X += m_MouseState.lX;
m_Y += m_MouseState.lY;

Share this post


Link to post
Share on other sites
Thank you both for your replies! Luckily all I had to do was rebuild it, not get into the down and dirty debugging... Thank you again.

Share this post


Link to post
Share on other sites