PDA

View Full Version : DC you need a log file to debug CTD


imported_PixelDude2K
12-02-2002, 09:33 PM
I'm a game programmer and there were times where my own game crashed to the desktop - not having some kind of log makes it really hard to diagnose the problem. Im not telling you how to program or anything, but I noticed IronStorm lacked a few programming tricks.

I made a log file class where I provided a function that writes incremental lines to a file and saves it before it returns to the game, for instance:

(Note this code is off the top of my head)
</font><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
void DebugLog(char *string)
{
char szCRLF[3];
szCRLF[0] = 10;
szCRLF[1] = 13;
szCRLF[2] = 0;


FILE *fp;
fp = fopen(&quot;c:\\logfile.txt&quot;, &quot;wb&quot;);
if(!fp) return;

seek(fp, SEEK_END,0);
write(string, sizeof(string), 1, fp);
write(szCRLF, 2, 1, fp);

close(fp);
}</pre><hr /></blockquote><font size="2" face="Verdana, Helvetica, sans-serif">I then called this function before every "suspect" part in my game, for instance if I was about to fill a vertex buffer, I would call DebugLog("About to fill vertex buffer at line xxx"); and so on...

It slows down the game a bit due to the constant file opening and closing but it sure diagnoses those pesky bugs.