Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


What makes Debug different from Release?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
20 replies to this topic

#1 Akashi   Members   -  Reputation: 268

Like
1Likes
Like

Posted 16 October 2012 - 08:37 AM

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, 16 October 2012 - 08:49 AM.


Sponsor:

#2 Olof Hedman   Crossbones+   -  Reputation: 2901

Like
7Likes
Like

Posted 16 October 2012 - 08:41 AM

Debug mode enables lots of runtime checks.
You are somewhere trashing your arrays in release mode too, you are just "lucky" it hasn't shown as a bug yet.

Edited by Olof Hedman, 16 October 2012 - 08:41 AM.


#3 littletray26   Members   -  Reputation: 267

Like
1Likes
Like

Posted 16 October 2012 - 09:05 AM

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! Posted Image

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

Edited by littletray26, 16 October 2012 - 09:06 AM.

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#4 stitchs   Crossbones+   -  Reputation: 1307

Like
1Likes
Like

Posted 16 October 2012 - 10:26 AM

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.

#5 UltimaX   Members   -  Reputation: 467

Like
3Likes
Like

Posted 16 October 2012 - 11:01 AM

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, 16 October 2012 - 11:02 AM.


#6 Josh Petrie   Moderators   -  Reputation: 3177

Like
6Likes
Like

Posted 16 October 2012 - 11:12 AM

The difference between Debug and Release is whatever you define it to be.

"Debug" and "Release" are idioms of Visual Studio (and many other IDEs) -- they are the names of default build configurations generated for a solution/project/whatever-your-IDE-calls-it. Generally, the "debug" configuration does no optimization and enables a bunch of extra sanity checking and safety mechanisms that are not present in the "release" configuration (which also enables optimizations). Almost all of the options in the configuration correspond directly to parameters that can be given to the compiler and linker and any other tools used to actually build your project.

Every major IDE that supports these kinds of configurations also allows you to modify them as you need to, and usually to define additional ones as well.

Josh Petrie | Game Developer, Undead Labs


#7 demonkoryu   Members   -  Reputation: 976

Like
0Likes
Like

Posted 17 October 2012 - 05:57 AM

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.

#8 Akashi   Members   -  Reputation: 268

Like
1Likes
Like

Posted 18 October 2012 - 10:31 AM

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.

#9 Akashi   Members   -  Reputation: 268

Like
0Likes
Like

Posted 23 December 2012 - 10:07 PM

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?



#10 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 23 December 2012 - 10:13 PM

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 :)!).


I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#11 Trienco   Crossbones+   -  Reputation: 2207

Like
1Likes
Like

Posted 24 December 2012 - 12:55 AM

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").


f@dzhttp://festini.device-zero.de

#12 Olof Hedman   Crossbones+   -  Reputation: 2901

Like
1Likes
Like

Posted 24 December 2012 - 04:41 AM

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, 24 December 2012 - 04:42 AM.


#13 Khatharr   Crossbones+   -  Reputation: 3030

Like
0Likes
Like

Posted 24 December 2012 - 05:43 AM

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.)


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#14 Akashi   Members   -  Reputation: 268

Like
0Likes
Like

Posted 24 December 2012 - 02:04 PM

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.



#15 SimonForsman   Crossbones+   -  Reputation: 6167

Like
0Likes
Like

Posted 24 December 2012 - 02:26 PM

<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, 24 December 2012 - 02:27 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#16 Khatharr   Crossbones+   -  Reputation: 3030

Like
0Likes
Like

Posted 24 December 2012 - 10:02 PM

<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


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#17 Akashi   Members   -  Reputation: 268

Like
0Likes
Like

Posted 26 December 2012 - 03:04 PM

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.



#18 Satharis   Members   -  Reputation: 1031

Like
1Likes
Like

Posted 26 December 2012 - 03:13 PM

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.



#19 iMalc   Crossbones+   -  Reputation: 2313

Like
1Likes
Like

Posted 26 December 2012 - 04:12 PM

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, 26 December 2012 - 04:13 PM.

"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

#20 L. Spiro   Crossbones+   -  Reputation: 13958

Like
0Likes
Like

Posted 26 December 2012 - 05:37 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS