Jump to content


Object not available in debug watch menu

c++

7 replies to this topic

#1 TTTNL

    Member

  • Members
  • PipPip
  • 48 posts

Posted 21 February 2013 - 12:44 PM

I've been following the "Introduction to C++ with Game Development" programming tutorial and i've finished part 12. I started working on my own demo game using the template from said tutorial.

I have two classes:
playerBubble

class playerBubble
{
public:
int x, y, Mx, My, rad;

playerBubble()
{
  x = 100;
  y = 100;
  rad = 32;
}

void MoveUp()
{
  if ( y >= 0 )
  {
   y--;
  }
}
void MoveDown()
{
  if ( y <= 480-64)
  {
   y++;
  }
}
void MoveRight()
{
  if ( x <= 640-64 )
  {
   x++;
  }
}
void MoveLeft()
{
  if (x >= 0)
  {
   x--;
  }
}
void Draw( Surface* a_Screen )
{
  spr_playerBubble.Draw( x, y, a_Screen );
}
} player;

enemyBubble.

class enemyBubble
{
public:

float y, speed;
int x, Mx, My, rad;
enemyBubble()
{
  x = 250;//rand() % 641 - 64;
  y = 500;//rand() % 50 + 500;
  speed = 0.1;
  rad = 16;
}
void Move()
{
  if (y <= -64)
  {
   if (speed < 1)
   {
	speed += 0.02;
   }
   srand ( rand() );
   y = 250;//rand() % 100 + 500;
   x = 500;//rand() % 641 - 64;
  }
  y -= speed;
}
void Draw( Surface* a_Screen )
{
  spr_enemyBubble.Draw( x, y, a_Screen );
}
} enemy;

This is my "Tick" function:

void Game::Tick( float a_DT )
{
m_Screen->Clear( 0 );

  
if (GetAsyncKeyState( VK_UP ))
{
  player.MoveUp();
}
if (GetAsyncKeyState( VK_DOWN ))
{
  player.MoveDown();
}
if (GetAsyncKeyState( VK_LEFT ))
{
  player.MoveLeft();
}
if (GetAsyncKeyState( VK_RIGHT ))
{
  player.MoveRight();
}
enemy.Move();

enemy.Draw( m_Screen );
player.Draw( m_Screen );
}

I put a break at the last line the Tick function and when i open the watch menu i can type in my object "player" and get all the variables of that object. But when i type in "enemy" i see this:

Posted Image

As you can see the type of object "player" is it's accommodating class but the type of object "enemy" is enemy itself so there is clearly something going wrong here but the demo itself is working as it should.


Can someone please help me figure out what's wrong here?

Edit while making this post:

I just figured out that it does work when i edit the source code but don't delete anything (an enter, backspace or similar) and press F5 again, i don't even have to remove the breakpoint. So you would think that it would work if i ran the game and a after a few seconds placed the breakpoint, no it doesn't, i need to edit the source code while not changing anything except white space and it works. But i have to do this everytime i start debugging so that is no option. How can this happen?

I used Hyperdesktop to capture the screenshots, great program for use in situations like this. You have shortcuts to take a screenshot from your screen, the active window or a self drawn box. Then it uploads that to Imgur and the direct image link is copied to your clipboard so you just have to paste it in the add image box here.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 21 February 2013 - 05:32 PM

Are you running in a Debug build or a Release build? In Release builds, optimization can foul up the debugger's ability to look at local variables. But it sounds like "enemy" is a global variable here, so I'm not sure this is the issue. Anyway, if you're in a Release build it's worth switching to Debug to see if that helps. You can also disable optimization for specific files or even specific functions using #pragma optimize (google it).

As for the problem with adding a breakpoint, I didn't completely understand what you were saying, but while running in the debugger you should be able to add/remove breakpoints at any time before or during program execution. Editing the source code while debugging can actually foul things up sometimes because source no longer matches the version that was last compiled, so that's best avoided.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 TTTNL

    Member

  • Members
  • PipPip
  • 48 posts

Posted 21 February 2013 - 05:57 PM

View PostReedbeta, on 21 February 2013 - 05:32 PM, said:

Are you running in a Debug build or a Release build? In Release builds, optimization can foul up the debugger's ability to look at local variables. But it sounds like "enemy" is a global variable here, so I'm not sure this is the issue. Anyway, if you're in a Release build it's worth switching to Debug to see if that helps. You can also disable optimization for specific files or even specific functions using #pragma optimize (google it).

As for the problem with adding a breakpoint, I didn't completely understand what you were saying, but while running in the debugger you should be able to add/remove breakpoints at any time before or during program execution. Editing the source code while debugging can actually foul things up sometimes because source no longer matches the version that was last compiled, so that's best avoided.

It's running a debug build. I don't have any problems with breakpoints, let me explain step by step what I do and whats working or not:

1. I place a breakpoint at the end of my tick function
2. i press F5 to start debugging
the game stops at the breakpoint and i see this in my watch window:
Posted Image

3. I click on an empty line in my source code and press enter
no code has been changed and the game is still running in debug mode and still stopped at the breakpoint
4. I press F5 again without removing the breakpoint
the game is still stopped at the breakpoint and this is my watch window:
Posted Image

Suddenly the enemy is visible in the watch menu as the corresponding class enemyBubble and with correct variables

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 21 February 2013 - 06:06 PM

Very strange. I've never seen a problem like that. You might try a full clean build of your project just in case there is some weird stale state hiding somewhere that's causing this. If that doesn't help, you might try reinstalling Visual Studio (ugh).
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 TTTNL

    Member

  • Members
  • PipPip
  • 48 posts

Posted 21 February 2013 - 06:12 PM

the output window states "Edit and Continue build started" after i press F5 in step 4.

What do you mean by making a full clean build? I'm fairly new to Visual Studio and C++.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 21 February 2013 - 06:20 PM

View PostTTTNL, on 21 February 2013 - 06:12 PM, said:

What do you mean by making a full clean build? I'm fairly new to Visual Studio and C++.

Go to the Build menu and choose "Clean Solution" - this will wipe out all the files created by the compilation process, including the .exe and all the intermediate files, debugger databases and whatnot. Then build the solution again (press F7). It will recompile everything from scratch, rather than doing an incremental build.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 TTTNL

    Member

  • Members
  • PipPip
  • 48 posts

Posted 21 February 2013 - 06:34 PM

View PostReedbeta, on 21 February 2013 - 06:20 PM, said:

Go to the Build menu and choose "Clean Solution" - this will wipe out all the files created by the compilation process, including the .exe and all the intermediate files, debugger databases and whatnot. Then build the solution again (press F7). It will recompile everything from scratch, rather than doing an incremental build.

Yes that worked, thank you so much! :D

#8 TheNut

    Senior Member

  • Moderators
  • 1699 posts
  • LocationThornhill, ON

Posted 21 February 2013 - 07:08 PM

Debugging data will be excluded if you tend to change things while the compiler or code is running. It's not uncommon either for Visual Studio to forget some source files were updated and not recompile them. By cleaning your project, you force Visual Studio to recompile everything fresh, which as you've seen corrected your problem. You could optionally select the "Rebuild All" option to do both steps (clean + build) at the same time. The Edit and Continue compiler flag does allow you to make code changes during debugging, but you need to be in a debug state for the code to get recompiled when you resume. I would also recommend avoid doing this excessively in a single session. If you're making a lot of changes, it's best to do a proper recompile otherwise a whole lot of other issues can occur.
http://www.nutty.ca - Being a nut has its advantages.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users