views:

419

answers:

7

Hi everybody,

I'm working on a little C++-Game in Visual Studio 2008. I want to see the content of a vector after a couple of seconds or after I pressed some buttons. Breakpoints are useless in this case, because they stop me at every call of the gameloop (~60 times per second). How do I debug in this case?

Thanks!

+2  A: 

You can set conditional breakpoints, i.e. breakpoints which hit at a certain position only when a given expression is true. You can, for example, set a breakpoint which hits only every nth time in a loop.

JesperE
+1  A: 

you can use a simple output to the console.

say you want to display an integer, you can simply use printf for example:

printf("the number is %d \n", vectorArray.at(place) );
This won't show unless A) your app is linked as a console application or B) you have opened a console in your app and redirected stdout to it.
Andreas Magnusson
+1  A: 

Setup an elapsed timer and something extremely basic.

if elapsedTime > 3 seconds: hits your break point, check out your vector

Or if you want to stop on a very specific point, just flag a counter to keep track of how many frames you've done.

Hawker
+5  A: 

Use function OutputDebugString from Windows API. You can call it anytime you want e.g. every 100th loop in your code.

Function info is here

Please read all comments on this page - some people claim that in your IDE (VS2008) output of this function is shown in "Immediate Window" not the "Output".

Wacek
+1  A: 

Along with conditional breakpoints you can also have the breakpoint write the vector values to the console and not stop.

Right click on your breakpoint and select "When Hit" click "print a message" and then add your values to the message in curly braces. Use the "Hit Count" to have the breakpoint execute after so many cycles. The "Condition" option is also useful for setting the breakpoint dependent on a certain value in your variables.

Maggie
A: 

You can also set your breakpoint inside a piece of conditional code, e.g.:

if(keyPressed('S'))
{
  int a = 42; // <-- set breakpoint here
}

The pro vs a conditional breakpoint is that the condition can be a bit more complex, the con is that each time you need to change the condition, you need to compile and link your app.

Andreas Magnusson
A: 

i found out that if you include and use fprintf(stdout,"")

it returns a command prompt on the screen while your program is still running

ssmithstone