The easiest way to debug a game that I know of is using printf or cout and tell Visual C++ 2005 to redirect the output to a file. To do that, simply go to Project > MyProject properties. Under Configuration Properties > Debugging > Command Arguments and write “> debug.txt”. This will redirect everything that is written on the standard output to debug.txt
Another way is to use the OutputDebugString. Everything printed with that function will be shown in the Output section of the debugger. Here’s a function that I use (source : unixwiz.net)
#include "windows.h"
#include "stdio.h"
#include "stdarg.h"
#include "ctype.h"
void __cdecl odprintf(const char *format, ...)
{
char buf[4096], *p = buf;
va_list args;
int n;
va_start(args, format);
n = _vsnprintf(p, sizeof buf - 3, format, args); // buf-3 is room for CR/LF/NUL
va_end(args);
p += (n < 0) ? sizeof buf - 3 : n;
while ( p > buf && isspace(p[-1]) )
*--p = '\0';
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugString(buf);
}
And use it like this :
...
odprintf("Cannot open file %s [err=%ld]", fname, GetLastError());
...
If you know easier way to debug or would like to point out that one of those two methods aren’t recommended, post a comment.
0 Response to “Easy way to debug your game”