views:

44

answers:

4

I'm so tired of this happening. I'm working in Visual studio using C++, and go a little to far in developemnt before attempting a release build/run cycle, only to find my release build crashes. It leaves me no way to fix the problem beyond to hack out big chunks of code looking for all potential violators. Anyway, If I go into my "release" project properties and enable the debug database for "Edit and Continue", and DON'T even enable Debugging in the linker, the Release version runs perfectly.

OK, I do appreciate any input as to what kinds of thing to look for to properly get my Release version to work, but dare I ask this question: "Who Cares"? I understand that if the linker does in fact link with DEBUG versions of runtime and windows libraries, that the program probably won't run on any system that doesn't have VStudio installed. But what about what I'm doing... just letting the compiler DEBUG format set to "Program Database for Edit & Continue (/ZI)". It hardly makes a 1K difference in the sixze of the application, and if it won't stop the EXE from working, maybe I should just leave it set that way? Or am I asking for trouble?

--Randy

A: 

I think you need to identify what practices/code you have that cause crash in Debug but not Release.

If you can figure that out, you can identify what you need to do differently.

In addition, "I'm working in Visual studio using C++, and go a little to far in developemnt before attempting a release build/run cycle" indicates to me that you might want to develop more discipline in your development practice. You might want to spend a bit of time learning some test-driven development techniques; I found that those improved my code/compile defect rates.

sheepsimulator
A: 

I use a single build instead of separate debug and release builds: see "Separate ‘debug’ and ‘release’ builds?"

There are normally several differences between debug and release builds, e.g:

  • Which version of the run-time libraries?
  • Compiler optimizations?
  • Incremental linking?
  • Edit and continue?
  • Symbolic debug information?

You can in fact use these in any combination. The only thing that would stop your software running on a clean machine would be using the debug versions of the run-time libraries.

I usually switch off edit-and-continue, and incremental linking, because I've found these to be buggy in the distant past.

ChrisW
Jason Williams
@Jason Williams - Thanks for saying they're good now. The last time I used MSVC was for Windows Mobile: which has a slow debug cycle (because it has to include loading/reloading newly-built software onto the device or emulator and then restarting it), so E also, I wouldn't use incremental linking in a release build (e.g. because it increases the size of the executable), so I wouldn't use it at all (because I only do release builds).
ChrisW
@ChrisW: You don't do debug builds - how do you debug your code?! You shouldn't use incremental link on a release build (you ideally want a release to be a full clean build) but it saves a lot of time on debug builds (unless your app is tiny).
Jason Williams
Well thanks everyone. I guess i was hoping to hear some way to force DEBUG more to behave more like RELEASE, or some tool that would help me narrow my search for the issue, or maybe some options memory initialization options the compiler adds in DEBUG mode which I could alter. But the bottom line is, yes I HAVE to fix this, and I agree with everyone's assessment that I can't just let it go.
Randy
@Jason Williams - "how do you debug your code?!" - see http://stackoverflow.com/questions/420343
ChrisW
@ChrisW: Oh, I see. A release build with *debugging information* is just a debug build in my book. I'll debug a (real) release build if I can't repeat a problem in a debug build, but in the latter case I'm all for using every tool at my disposal to make the debugging process more efficient and effective. WHich seems to be what youre advocating, except that you dont turn those tools on by default?
Jason Williams
+1  A: 

"Who cares?" ... well, you should.

The fact that the release build crashes indicates there is something wrong with it.

If turning on debug symbols "fixes" it, then you have a magic fix that you don't understand. Why does it fix it? Can you rely on this fix working on every PC your software is installed on?

The symptoms you describe suggest that you are corrupting memory somewhere (a buffer overrun error most likely) and that addition of debugging symbols rearranges or pads out your code in such a way that you can "get away with it" because the memory corruption doesn't happen to hit anything vital.

But you can't really rely on such a fix. It undermines all confidence in your application, and it will bite you one day (such a fix could easily stop "working" the next time you compile your app)

You need to isolate what it is that causes this problem - if it happens more than once then you haven't learned anything from the last time you fixed it. It's not "normal" for an application to run in debug but not in release, so there must be something you're doing wrong - you need to work out what it is and fix it so that you avoid such bugs in future. (e.g. If it's a buffer overrun it may simply be that you are allocating a buffer of "n" elements and then accessing element "n" - you should only access elements 0 to (n-1). THis is very easy to fix once you understand how to write such code... but you have to put in a bit of effort to work out what it is youre doing wrong)

Jason Williams
Thanks. Of course you're right. It still was a fiar question. The notion that Microsoft could have issues in their development system causing things like this through no fault of the application code itself is not a possibility I should discount without asking in a forum like this.
Randy
@Randy: It's true that dev tools sometimes introduce issues, but in most cases it's simply a programming error. Even if it's a tool-related problem, it's worth investigating it to try to understand why and/or where it's happening - maybe you can change the settings for, or reinstall/upgrade the faulty tool to fix it.
Jason Williams
I'll say! I DID find the problem, and I sure am glad I dug into it. At least I'll come back after the 4th of July weekedn without having to starer it in the face then! :-) It was a pretty nasty error too, and one that a compiler could never catch! Not enough space to explain here in a "comment", but yeah... it would have bitten me eventually for sure!Yeah I guess I've re-learned a few lessons here. If it crashes only when the moon is full, then plan on some late nights once a month until it works. :-)
Randy
Cool. Yeah, it doesn't matter how rare or hard to repeat a problem is, once you see it you know that something's not right, and there's really no option but to try to fix it. Occasionally you'll get a bug that you can't track down and you have to say "If we don't see this again for 3 months we'll have to assume it's been fixed by accident", which really sucks. But in most cases you'll (eventually) track something down.
Jason Williams
A: 

Yes, you're asking for trouble. From the sound of things, you're writing code that contains undefined behavior, and happens to (at least appear to) work under certain circumstances -- but it's still almost certainly wrong (yes, some compilers have optimization bugs so correct code doesn't work when optimized -- but these are fairly rare).

Jerry Coffin