13 Replies - 3249 Views - Last Post: 16 March 2011 - 06:29 PM Rate Topic: -----

#1 DivideByZero  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 240
  • View blog
  • Posts: 551
  • Joined: 02-December 10

How do you debug your games?

Post icon  Posted 13 March 2011 - 05:57 AM

I'm just curious if there is an easier way than what I'm doing, or if there is only one way to do it.

Debugging procedural programs is easy due to the code always following some sort of order.
So when I debug I just check the values of the variables and follow the program through until I get to the bug. Simple.

But I am now trying to debug my 3D game where I need to know whether me pressing W is affecting the gameobject or not, and as far as I know there's no way to see if it does or not.
The screen goes to a frozen state and pressing W to see if it affects my code does nothing other than adds W's to my code :S

So I'm kinda curious as to how you debug an event driven application such as games.
Any pro tips/tricks for new game programmers like me?

Thanks in advance :)

This post has been edited by stayscrisp: 14 March 2011 - 05:45 AM


Is This A Good Question/Topic? 1
  • +

Replies To: How do you debug your games?

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: How do you debug your games?

Posted 13 March 2011 - 06:30 AM

Debugging a game is almost same as debugging any other software application. Logs, traces, message printing etc.

Like if you want to check if a particular key triggers something or not, put a statement, in the function attached to that key, that pop ups a message box.
So you know that the function actually gets triggered on the key press.
Was This Post Helpful? 1
  • +
  • -

#3 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How do you debug your games?

Posted 13 March 2011 - 10:32 AM

I wouldn't advise using messageboxes as that can remove focus from the game and cause it to crash. The standard way is to have a file logging system in place, or print activity to debug console and even values in the game screen itself. If debugging graphics you will usually show all primitives to observe directly what is going on.

Sometimes, if the game is large you will find yourself investing a significant amount of time developing the debug system as well.
Was This Post Helpful? 3
  • +
  • -

#4 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 562
  • Joined: 24-July 08

Re: How do you debug your games?

Posted 13 March 2011 - 02:10 PM

I to agree. I create a global ofstream and a log function with a message like so.
ofstream fout("game.log", ios::app); //so it doesn't erase prev info
bool log(char * msg)
{
   cout << "LOG: " << msg << endl;
   if(!fout)
   {
        cout << "Unable to write to file" << endl;
        return false;
   }else{
        fout << "LOG: " << msg << endl;
        return true;
   }
}
/*Then you can create a Error function the same way
  just replace "LOG: " with "ERROR: "*/


I use this method on all programs.
Was This Post Helpful? 2
  • +
  • -

#5 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1026
  • View blog
  • Posts: 4,282
  • Joined: 14-February 08

Re: How do you debug your games?

Posted 13 March 2011 - 04:44 PM

I have a few lines of code that do this stuff for me, its just a few utility functions that I can add to a project at the start. Something similar to this:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

class ErrorReporting
{
public:

	static ErrorReporting* Instance()
	{
		static ErrorReporting s_error;
		return &s_error;
	}

	void ReportError(string error)
	{
		cout << error << "\n";
	}

	void ReportErrorToFile(string error)
	{
		m_ofstream << error << "\n"; 
	}

private:

	ErrorReporting() 
	{ 
		m_ofstream.open("errors.txt", ios::out);
	}

	ofstream m_ofstream;
};



int main()
{
	ErrorReporting::Instance()->ReportError("Oops there has been an error");

	ErrorReporting::Instance()->ReportErrorToFile("Oops! there has been an error, better log it");

	cin.get();

	return 0;
}



It may seem a little overkill to wrap up printing to the console but I find it quite nice and easy to read. you will probably also want to wrap the printing to only run if debug is defined, which could be done in your header file.
Was This Post Helpful? 2
  • +
  • -

#6 (Cryptic)  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 13-January 11

Re: How do you debug your games?

Posted 13 March 2011 - 07:30 PM

If your programming on linux, then you can just cout or printf even if its a graphical program. Thats the easiest method I know. The hard part is writing a wrapper for your program so that it compiles on whatever platform you intend it to be played on. But with this you can't really use DirectX.
Was This Post Helpful? 1
  • +
  • -

#7 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1026
  • View blog
  • Posts: 4,282
  • Joined: 14-February 08

Re: How do you debug your games?

Posted 14 March 2011 - 05:21 AM

Going back to the OP problem, even though a game is more OO you can still usually follow it in a logical way just like a procedural program, there's just more to step through. For example you could set a break point in the place where you press the W key, press it once and the program breaks, then you can step through the code until you get to your player movement code, or the other way around.

You will eventually get then hang of debugging in this way :)

This post has been edited by stayscrisp: 14 March 2011 - 05:53 AM

Was This Post Helpful? 1
  • +
  • -

#8 (Cryptic)  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 13-January 11

Re: How do you debug your games?

Posted 14 March 2011 - 10:37 PM

Oh, there's a problem with debugging that I haven't solved or have a solution too.

That is sometimes when writing code, for example; writing a c/c++ code that writes and reads external text files. The debugger doesn't work as expected (this was a while back). Anyone got a solution to this?
Was This Post Helpful? 0
  • +
  • -

#9 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How do you debug your games?

Posted 15 March 2011 - 07:37 AM

What do you mean that the debugger doesn't work as expected? If I suspect the values read are corrupted I just write them out to the debug console as they are read.
Was This Post Helpful? 0
  • +
  • -

#10 (Cryptic)  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 13-January 11

Re: How do you debug your games?

Posted 15 March 2011 - 08:18 PM

View PostButchDean, on 15 March 2011 - 07:37 AM, said:

What do you mean that the debugger doesn't work as expected? If I suspect the values read are corrupted I just write them out to the debug console as they are read.


How do I do that with native C++ ? (using Visual Studio Express)
Was This Post Helpful? 0
  • +
  • -

#11 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How do you debug your games?

Posted 15 March 2011 - 08:41 PM

View Post(Cryptic), on 16 March 2011 - 03:18 AM, said:

View PostButchDean, on 15 March 2011 - 07:37 AM, said:

What do you mean that the debugger doesn't work as expected? If I suspect the values read are corrupted I just write them out to the debug console as they are read.


How do I do that with native C++ ? (using Visual Studio Express)

A quick solution is OutputDebugString(). :)
Was This Post Helpful? 1
  • +
  • -

#12 (Cryptic)  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 13-January 11

Re: How do you debug your games?

Posted 16 March 2011 - 01:46 PM

View PostButchDean, on 15 March 2011 - 08:41 PM, said:

View Post(Cryptic), on 16 March 2011 - 03:18 AM, said:

View PostButchDean, on 15 March 2011 - 07:37 AM, said:

What do you mean that the debugger doesn't work as expected? If I suspect the values read are corrupted I just write them out to the debug console as they are read.


How do I do that with native C++ ? (using Visual Studio Express)

A quick solution is OutputDebugString(). :)


Excellent. Thanks ButchDean. I don't know how you found that site. I've searched high and low, everything gives me C# alternatives or C++ but for .Net or requires some sort of system.funnything.dunno includes/imports.
Was This Post Helpful? 0
  • +
  • -

#13 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How do you debug your games?

Posted 16 March 2011 - 02:21 PM

No problem. It was shown to me by a fellow programmer about three years ago. Bookmark it, it's a valuable site that many games people have learned from (including me!). :)
Was This Post Helpful? 0
  • +
  • -

#14 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,303
  • Joined: 22-October 08

Re: How do you debug your games?

Posted 16 March 2011 - 06:29 PM

I debug my php games with my own debug clas. This class gets load time, query time page ownership ect. If any errors are found it will add it to the log.
Thats how i debug my games.

Thanks,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1