Object not available in debug watch menu

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 21, 2013 at 12:44 c++

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:

9kl3ryN.png

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.

7 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Feb 21, 2013 at 17:32

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.

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 21, 2013 at 17:57

@Reedbeta

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:
    9kl3ryN.png

  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:
    mTMIrCu.png

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

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Feb 21, 2013 at 18:06

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).

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 21, 2013 at 18:12

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++.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Feb 21, 2013 at 18:20

@TTTNL

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.

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 21, 2013 at 18:34

@Reedbeta

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

6837d514b487de395be51432d9cdd078
0
TheNut 179 Feb 21, 2013 at 19:08

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.