Jump to content
  • Advertisement
Sign in to follow this  
LetsDoThis

Best way to debug a code in the game loop?

This topic is 1172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this problem where it takes me hours of just figuring out the bug on the game I am trying to do.

 

Most the debugging method I do is that I just put a

Debug.Writeline()

on code that I suspect is the culprit. This is obviously becomes confusing when the project becomes larger and theres more class involve and passing things to other class.. The other way is that I use a break point. But what if the bug happens just in the middle of the game? It will take a thousand loop just to get there and break point is not really a good option for that i think.

 

For all game programmers out there. What is your best way of figuring out the bug in your project?

 

 

PS: I am using C#/XNA and Visual studio 2013

Edited by LetsDoThis

Share this post


Link to post
Share on other sites
Advertisement

I don't see any language or platform tags on your post, but some debuggers allow you to set conditional break points, which will only trigger if your code goes through the statement and if a variable has a certain value. Some environments also allow you to create a statement that will trigger a debug break, like __debugbreak() in MSVC. Otherwise, most semi-modern loggers allow you to have logging hierarchies, and enable different logging levels for different branches of the hierarchy. Ex: by default you might have things logging at warning, but for the suspected subsystem log at info or debug. 

Is this the one your talking about debugbreak()

Share this post


Link to post
Share on other sites


In many languages you can also create crash dumps, where if an assertion fails on a user's PC, they can send you the crash dump, and you can open it in your debugger as if it's just hit a breakpoint on that line, and use the debugger to see exwctly to what's gone wrong.

 Will this work as well if say the variable is set to false instead of true?  Cause whenever i hear crash dumps i think its mostly the program crashes cause of some random exception?

 

and uhm do you have a link on how to do this? Thanks

Share this post


Link to post
Share on other sites

Will this work as well if say the variable is set to false instead of true?

 

assert breaks on an expression that evaluates to "false."

 

If you want to break when something is true, instead, use:

 

assert( some_condition != false );

 

or simply:

 

assert( !some_condition );

 

 

 


i think its mostly the program crashes cause of some random exception?

 

Ain't no such thing as a "random" exception**. Something in the program caused the condition - reading or writing beyond the end of a buffer, out-of-memory, a combination of conditions that the programmer didn't anticipate, failure of the application to determine if the user's hardware is compatible with the demands of the program, etc. Most of those situations can be avoided with good programming practice.

 

** discounting lightning strikes, EMPs, coffee spilled on the keyboard, etc.

Edited by Buckeye

Share this post


Link to post
Share on other sites


PS: I am using C#/XNA and Visual studio 2013

As an addition to above suggestions there is also one more thing you can do. In menu Debug->Exceptions be sure to check also "Thrown" column of relevant exceptions (it is unchecked by default). That way it will break at the time any exception is thrown and you will be able to debug the issue.

Share this post


Link to post
Share on other sites
I tend to do the following:

Use the built in debugger to trace execution and break on error,

Use a wrapper class around OutputDebugString() to give it iostream like behaviour and use it judiciously in debug builds,

Use assertions as much as possible to ensure what you think should be happening is actually happening.

I have also been known to put a regression test suite into my app or game so you can run it in some special way e.g. With a command line parameter and rather than entering the main loop, it initialises all systems and performs tests with known parameters, logging which functions give unexpected results. You can tie this into the release process to check your new features haven't broken old ones. Very strongly advised.

Share this post


Link to post
Share on other sites

I have also been known to put a regression test suite into my app or game so you can run it in some special way e.g. With a command line parameter and rather than entering the main loop, it initialises all systems and performs tests with known parameters, logging which functions give unexpected results.

 Im lost on this part. Can you give me a simple example or link to explain just how this works or how to do this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!