• Advertisement
Sign in to follow this  

What makes Debug different from Release?

This topic is 1853 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've been working on a project for awhile, and since I often send the executables to my friends to test, I tend to debug in Release mode. But I changed it back to Debug, and suddenly, a bunch of stuff is going wrong. How much different can it be that it pretty much destroys the data in my arrays? I'm using Microsoft Visual Studios 2010 Express, and when I switch to Debug from Release, at a certain point in my code, one of my two dimensional character arrays becomes half filled with a special character I use to test for collisions. I don't think it's necessary to show my code. I don't want to find where I specifically went wrong, just what makes Debug have this dramatic of a difference. Edited by StoneMask

Share this post


Link to post
Share on other sites
Advertisement
When you're in Release mode you're sacrificing a lot of the runtime debugging Visual Studio does. In reality, however, your array is trashed in both Debug and Release mode. In Release mode you just can't tell because you're not debugging it! tongue.png

I would suggest going into Debug mode and stepping through your code to find where the problem is. Edited by littletray26

Share this post


Link to post
Share on other sites
Just a little addition as I don't think much more can be added; It is always best to code + build in debug mode as this helps to iron out as many potential bugs your program has, before you set it to compile in Release. Release building is for (hence the name) deployment of your product to the client.

Just out of curiosity, did your VS set you to debugging in Release by default?

Regards,

Stitchs.

Share this post


Link to post
Share on other sites
Also, keep an eye on unitialized variables. Debug mode will initialize variables that have not been explicitly initialized. Try compiling with the /RTCu flag set. See here: http://msdn.microsof...(v=vs.100).aspx for more information. Edited by UltimaX

Share this post


Link to post
Share on other sites
In addition, "Debug" configurations most often compile full symbols into your executable, allowing you to easily debug runtime errors "just in time". There's also the option of creating external symbol database files for "Release" mode executables; however, optimized executables often reorder, alias, and/or eliminate code and data, and the symbols and code representation may not be accurate or readable anymore in that case.

Share this post


Link to post
Share on other sites
Just out of curiosity, did your VS set you to debugging in Release by default?


No, I recently made a topic asking how to ship out a usable .exe, and they told me that I should build in release configuration. So instead of switching back all the time, I just got lazy and left it on Release. I have learned the error of my ways...

Thanks for the information everybody! If I have any other questions, I'll be sure to come back to this thread.

Share this post


Link to post
Share on other sites

So I made sure I was always set to Debug mode after this thread, and so far I haven't had any errors. But then I switched to Release to test something out, and now everything has been thrown into chaos again. Things are being drawn out of order, my functions are being called with the wrong parameters-- everything is out of whack. If I can't trust Debug mode to get rid of these things, then how will I know nothign will go wrong with different computers and settings? Do I just have to keep switching in between them and making sure both modes run correctly? What is happening? Why is it so drastically different to run in Release mode?

Share this post


Link to post
Share on other sites

In release mode, it creates a separate file (Called Release) for your project. You have to re-link Release Mode for it to work and include your Library DLL's and Files. I had your same problem with my first game (Pong :)!).

Share this post


Link to post
Share on other sites
So I made sure I was always set to Debug mode after this thread, and so far I haven't had any errors. But then I switched to Release to test something out, and now everything has been thrown into chaos again.

 

Which generally means that you still have some major bugs in your code and are simply lucky that those bugs don't have any visible consequences in debug mode, either because your data has a different and less tightly packed memory layout or because stuff is being initialized for you.

 

The most important lesson in programming: just because it compiles, doesn't mean it's working and just because it appears to be working, doesn't mean it isn't full of serious bugs. Especially when it comes to C/C++, "trial and error coding" will bite you and you should be knowing what you're doing every step along the way. Never "try" something and decide that if it doesn't crash right away it must be "correct" to do it that way.

 

If your bugs don't show in a debug build and a release build is too optimized or lacking debug symbols to be useful, you will want to copy your release configuration and change the settings, hopefully finding one where the bugs are still happening and you can decently debug. Otherwise, there is always caveman debugging, where you spam debug outputs all over the place to figure out where things are going wrong.

 

As for "how I can be sure it will work on other computers". That's why "testing" is a very complex subject of its own, involving unit tests, black/white box tests, regression tests and all kinds of other test strategies. Essentially writing tests will take up about the same amount of time as writing the actual code (at least if you want to do it "right").

Share this post


Link to post
Share on other sites
It's impossible for debug mode to catch all crazy things a human programmer can think of doing.
The checks are usually pretty basic, and if you for example use a pointer to modify memory, there is no check that that memory is actually allocated (and it can't know if it points to the data you think it points too)

There might be a check of the heap integrity the next time you allocate or free, but if you also have problems with leaks and how you allocate your memory, maybe this check never is run.

And if you allocate it on the stack, all things of wonderfully weird things can happen if you write outside your allocated area. On some platforms you might even change what line of code you return to at the end of your function...

These things are really just possible to get rid of with diligence, keeping the lifetime and ownership of your objects clearly defined, make sure all variables are initialized before you use them, and make sure pointers never point to uninitialized or deleted data or walks past the bounds of an array. Edited by Olof Hedman

Share this post


Link to post
Share on other sites
And if you allocate it on the stack, all things of wonderfully weird things can happen if you write outside your allocated area. On some platforms you might even change what line of code you return to at the end of your function...

 

You know I was just thinking yesterday that an array on the stack could do that with the correct negative index. That kind of thing makes me chuckle. (As you can see from my sig.)

Share this post


Link to post
Share on other sites

Well, the "platform" I'm using is the command prompt. Pretty much, my enemies don't write the "enemy" character to the array, but a bunch of garbage values that coincide with character values. So if I ever intersect with the enemies, sometimes their character value is equal to something else my character is supposed to interact with, so it'll make me enter a sort of bizarre black and white version of the normal dungeon that's generated, or it'll send me back into the same dungeon, which increases my difficulty level and regenerates the dungeon, so say I'm running towards an exit. Sometimes intersecting where an enemy object is will regenerate the dungeon, so I end up just running into a wall. It's kind of terrifying, kind of weird, but it's kind of cool at the same time. But eventually the enemy will touch me with a character that just changes my world setting to the overworld, so I'm stuck in a dungeon that behaves like the overworld, which is more boring. I'll post a video, probably.

 

I've isolated the problem to just my enemy objects. They're contained in a vector array of pointers to enemy objects. Without the enemies everything runs fairly well. I think that Trienco's "know what you're doing" advice is pretty good. Admittedly, I'm a bit weak in my knowledge about pointers.

Share this post


Link to post
Share on other sites
<blockquote class="ipsBlockquote" data-author="StoneMask" data-cid="5014010"><p>Well, the "platform" I'm using is the command prompt. Pretty much, my enemies don't write the "enemy" character to the array, but a bunch of garbage values that coincide with character values. So if I ever intersect with the enemies, sometimes their character value is equal to something else my character is supposed to interact with, so it'll make me enter a sort of bizarre black and white version of the normal dungeon that's generated, or it'll send me back into the same dungeon, which increases my difficulty level and regenerates the dungeon, so say I'm running towards an exit. Sometimes intersecting where an enemy object is will regenerate the dungeon, so I end up just running into a wall. It's kind of terrifying, kind of weird, but it's kind of cool at the same time. But eventually the enemy will touch me with a character that just changes my world setting to the overworld, so I'm stuck in a dungeon that behaves like the overworld, which is more boring. I'll post a video, probably.<br /> <br />I've isolated the problem to just my enemy objects. They're contained in a vector array of pointers to enemy objects. Without the enemies everything runs fairly well. I think that Trienco's "know what you're doing" advice is pretty good. Admittedly, I'm a bit weak in my knowledge about pointers.</p></blockquote><br />As a rule of thumb in C++ , do not use raw pointers unless you have a really good reason to do so, any object you have that deals with raw pointers must follow the rule of three and you always have to be careful when using the pointers. (It sounds as if your enemy objects are writing to memory that belongs to other objects).<br /><br />If you post the code for your enemy class (and its subclasses) i'm sure we can figure out where you are going wrong.


Edit: Whats wrong with the quoting ? Edited by SimonForsman

Share this post


Link to post
Share on other sites
<blockquote class="ipsBlockquote" data-author="StoneMask" data-cid="5014010"><p>Well, the "platform" I'm using is the command prompt. Pretty much, my enemies don't write the "enemy" character to the array, but a bunch of garbage values that coincide with character values. So if I ever intersect with the enemies, sometimes their character value is equal to something else my character is supposed to interact with, so it'll make me enter a sort of bizarre black and white version of the normal dungeon that's generated, or it'll send me back into the same dungeon, which increases my difficulty level and regenerates the dungeon, so say I'm running towards an exit. Sometimes intersecting where an enemy object is will regenerate the dungeon, so I end up just running into a wall. It's kind of terrifying, kind of weird, but it's kind of cool at the same time. But eventually the enemy will touch me with a character that just changes my world setting to the overworld, so I'm stuck in a dungeon that behaves like the overworld, which is more boring. I'll post a video, probably.<br /> <br />I've isolated the problem to just my enemy objects. They're contained in a vector array of pointers to enemy objects. Without the enemies everything runs fairly well. I think that Trienco's "know what you're doing" advice is pretty good. Admittedly, I'm a bit weak in my knowledge about pointers.</p></blockquote><br />As a rule of thumb in C++ , do not use raw pointers unless you have a really good reason to do so, any object you have that deals with raw pointers must follow the rule of three and you always have to be careful when using the pointers. (It sounds as if your enemy objects are writing to memory that belongs to other objects).<br /><br />If you post the code for your enemy class (and its subclasses) i'm sure we can figure out where you are going wrong.


Edit: Whats wrong with the quoting ?

 

You broke the internet. Merry Christmas. laugh.png

Share this post


Link to post
Share on other sites

lol

So I discovered the problem, kind of? It really didn't have anything to do with the way I was storing memory or anything. For some reason, the function I use to spawn the enemies and place them in an empty spot were, for some reason, placing them on top of collision blocks. I didn't program them to do anything when they're stuck in a collision block, but for some reason, they flip out and start teleporting me places.

Share this post


Link to post
Share on other sites
lol

So I discovered the problem, kind of? It really didn't have anything to do with the way I was storing memory or anything. For some reason, the function I use to spawn the enemies and place them in an empty spot were, for some reason, placing them on top of collision blocks. I didn't program them to do anything when they're stuck in a collision block, but for some reason, they flip out and start teleporting me places.

You mean you didn't think you did. Unless you're using someone else's code it is entirely likely and most likely true that you wrote something that is having an unintended consequence.

 

Short version: You probably did program them that way.

Share this post


Link to post
Share on other sites
The unfortunate thing is the the stuff that the debug build does for you to catch problems like using uninitialised variables, sometimes is also specifically what causes you to not find problems like using uninitialised variables.

I.e. The most common value in RAM is zero. So if you forget to NULL a pointer that should be NULL initially then often it will just work. So along come the Debug runtimes which initialise all your locals to 0xCC. Next up you have a bool variable which is supposed to be initialised to true, except that you forgot. Now under debug that will always act as if it were true initially since it is not zero. Switch back to release and then boom it starts out false most of the time.

Long story short, yeah you really do need to switch back and forth and check both from time to time. A good idea is to use a version control system and make sure that both debug and release builds are working each time before you check in the bit you were working on, or before merging it to the main branch or whatever. It's always good to have a working debug and release build version that you can compare with. But other than that, the rest of the time you can probably just use debug builds. Edited by iMalc

Share this post


Link to post
Share on other sites
Long story short, yeah you really do need to switch back and forth and check both from time to time.

As the only developer on my own engine I switch constantly, but I have noticed a trend in the professional world in which all developers on all teams in all companies in which I have worked build exclusively in debug mode for very extended periods of time, sometimes not checking release mode at all for up to 6 months. One project here had been going for about 9 months and since optimization is my job I asked the leader, “So how does it run in release mode?”, to which he replied, “We’ve never run it in release mode.”

That is why at my office I work almost exclusively in release mode, because as you say it is important for both to be tested constantly, and it seems no one else is going to do it.


L. Spiro

Share this post


Link to post
Share on other sites

Just to be clear on this issue, there's not actually anything that's inherently different between "Debug" and "Release". They're just 2 default configurations added to your project by Visual Studio, and by default they're configured such that Debug has optimizations off with debugging features enabled, while Release has has optimizations on with most debugging features disabled. In practice you're free to change the various settings however you want for each configuration, or even create new ones with arbitrary names. Where I work actually use more than just 2 configurations, with various things like optimizations, debug utilities, and asserts turned on and off depending on our needs. So for instance on my team we usually run most of our tools and build system with optimizations on (so it's not slow), but with asserts on so that we know when something goes wrong. Then when we push a build for artists and designers we use a configuration with asserts off.

Share this post


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

  • Advertisement