• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ChristianFrantz

debugging for beginners

8 posts in this topic

I've gotten the hang of c++ and DirectX so far, but when I create my own projects I have trouble debugging when I run into an error. I know how to set breakpoints and check for local variables, but when I miss an initialization or declaration I have a hard time finding the error. Are there any tutorials or books based just on debugging practices? Or is it a skill that you have to learn as you go?
0

Share this post


Link to post
Share on other sites
Most compilers generate a warning when you use a variable without initialization. If your compiler does not you might want to increase the warning level. It's usually not a bad idea to enable treating all warnings as errors as well (that might not be feasible when you take over a large project which does not build without warnings but it is a good habit to get into for a new project).

A lot of potential bugs can be eliminated by not ignoring warnings.

I'm not sure what you mean by "missing a declaration". In the context of C++ I don't see how this could be anything but a compiler error (which are thankfully the easiest to find problems which don't even need a debugger).
0

Share this post


Link to post
Share on other sites

I would say that if you can't find a problem with an initialization then you are probably writing some pretty messy code.

All variables should be initialized as soon as possible. They should almost always be at the top of the section or the global area. The only time when this isn't the case is when if you don't do something then you're never going to use the variable so why define it... Of course that is just an opinion.

 

You should also indent and comment, explaining the code in the code.

 

You don't have to do these things, but it does make debugging and having readable code that much easier.

1

Share this post


Link to post
Share on other sites

Or is it a skill that you have to learn as you go?

 

The reason programming is hard, and making games is hard, is because it is easy to make a mistake that is very hard to find.  Sometimes the program just crashes, and sometimes nothing works.  But there is no secret, shortcut, list of steps, or book that can help with this, for the same reason there is no set of steps for solving all word problems in math.  There are things you can try, but every problem is different.

 

But it is this process of making mistakes and figuring out what is wrong and fixing it that makes you a programmer.  Eventually you'll be working on a big project or something new and there will be a problem that you can't "Google" or get help with.  If you haven't paid your dues finding and fixing these little errors you won't be prepared for the tough ones.  

 

We all make silly mistakes like this when we started learning to code.  

 

Some suggestion:

 

1.  Make sure you understand EVERY SINGLE LINE of code.  When starting out, just cut-and-pasting code won't help you learn what you're doing.

2.  Using the debugger is good, but also, try debugging print statements.  Make a guess as to what is wrong, or what isn't wrong, and then prove it by logging something to the console.  You'll be surprised what you find.  Then leave those print statements there, just commented out, so you can turn them back on again if something else goes wrong.

3.  Try commenting everything out, and then adding one thing at a time, making sure everything is working as expected.

4.  When all else fails, try describing your problem to some else and/or have them look at your code.  It is really easy to miss something when you've been staring at the same function for four hours.

 

And hang in there.  Programming isn't easy.

Edited by Glass_Knife
2

Share this post


Link to post
Share on other sites

This is part of the reason I asked this question about pseudocode:

 

http://www.gamedev.net/topic/654225-how-does-your-pseudocode-look/

 

Also part of the reason I posted a link to this article about coding horrors:

 

http://www.gamedev.net/topic/652277-ugh-your-shorthand-is-too-short/

 

I agree that how the code is organized helps make debugging easier. 

 

Also the reason I wrote this small tutorial which, as BitMaster suggests, initializes variables first:

 

http://forum.maratis3d.com/viewtopic.php?id=793

0

Share this post


Link to post
Share on other sites
I know this is a bit late if your code is already bugged, but you should consider getting into the habit of unit testing your code as you write it.

For one thing it helps identify when new code breaks an existing system in an unexpected way. But also it will encourage you to really consider the awkward cases you might otherwise skip over. Often a test is the clearest specification of correctness, and if your test fails then you know you're not done. Conversely, if a robust and thorough test passes then have a beer.
0

Share this post


Link to post
Share on other sites
I had posted a thread a while back about an error I was having within a view frustum class. It turns out that I had two lines switched; I was trying to use an object before it was initialized. Even with using breakpoints and checking the local variables it still took forever to figure out where I messed up
0

Share this post


Link to post
Share on other sites

I have no idea how to use any debugger tool in the IDE so I'm used only to read the code and output results trough the printing function, the one that outputs "Hello Worlds".

This print function is my best friend so far.

 

That is how I debugg my games.

Edited by dragons
0

Share this post


Link to post
Share on other sites

I had posted a thread a while back about an error I was having within a view frustum class. It turns out that I had two lines switched; I was trying to use an object before it was initialized. Even with using breakpoints and checking the local variables it still took forever to figure out where I messed up

 

The question to ask is: how can that even happen?

 

Basic rules: minimize variable lifetime. Do NOT get into the annoying C-habit of dumping all variables at the beginning of a block. 9 out of 10 times, the is no excuse to split declaration and first assignment (hint: "assigning something later" is NOT "initializing").

 

Simple example:

{
   int var; //Bad
   int foo;
   //doStuff
   var = getData();   
   foo = calc(var);
}
 
//What happens if you add a line working with var?
{
   int var; //Bad
   int foo;
   //doStuff
   draw(var); //BUG
   var = getData();   
   foo = calc(var);
}
 
//Always declare at point of first use
{
   //doStuff
   const int var = getData();   
   const int foo = calc(var);
}
 
//Now this wouldn't even compile, saving you lots of time wasted on debugging
{
   //doStuff
   draw(var);
   const int var = getData();   
   const int foo = calc(var);
}
Edited by Trienco
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0