Jump to content
  • Advertisement
Sign in to follow this  
freeworld

compiling in release mode crashes but debug works?

This topic is 3760 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'm using vc++2005 express I'm trying to get a release build to work, but it keeps crashing on me as soon as the program calls a function from my .lib. when running the debug build everything works perfectly fine. does anybody have any ideas on how I can find the problem or common solutions without me posting a 1,000 lines of code? Sorry for being vague... any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Try changing the warning level to be more strict in debug mode. Maybe there's a couple of things that merit warnings when run together results in a crash. Good luck.

Share this post


Link to post
Share on other sites
a typical error a lot of people make with debug/release is something like this:

void CFoo::Test()
{
if ( m_pMyPtr )
{
m_pMyPtr->DoSomething();
}
}


the creator of this class did not initialize m_pMyPtr to zero, but in debug mode it will get a value of zero and in release mode it will be whatever happens to be on the heap.

so basically in debug mode you won't catch this mistake.. but in release it will crash.

hope this helps,
Peter Wraae Marino

Share this post


Link to post
Share on other sites
Quote:
Original post by Crisium
a typical error a lot of people make with debug/release is something like this:

void CFoo::Test()
{
if ( m_pMyPtr )
{
m_pMyPtr->DoSomething();
}
}


the creator of this class did not initialize m_pMyPtr to zero, but in debug mode it will get a value of zero and in release mode it will be whatever happens to be on the heap.

so basically in debug mode you won't catch this mistake.. but in release it will crash.

hope this helps,
Peter Wraae Marino


does it not initialize pointers only? I always thought pointers were defaulted to the OS's NULL value? would not initialzing other types such as float or integers cause the same problems?

I'll clean up my library I guess. Strange under VC6 I don't remember having these problems, and yes alot of the code in my lib is old enough to be back from those days.

Share this post


Link to post
Share on other sites
You should be initializing all variables.

I fixed a bug in a shipped game a couple years ago that worked "fine" in debug, but produced bad results in release. It was caused by an uninitialized boolean (it would be set to false in debug, but would be uninitialized in release mode, and would more often than not be true since true is any non-zero value).

Initialize member variables in the appropriate constructor, and initialize local variables when they're declared (unless you're careful to make sure they're initialized before use).

The same applies for any data type, but I find pointers and bools are the most problematic (mainly due to the way they are used).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!