Sign in to follow this  
LewsTherin

Hunting a magic bug

Recommended Posts

I recently recompiled my entire program to make sure things were still sane. Now, it crashes on startup. However, if I open it in a debugger (gdb) it works fine. How would I find out what's causing this magic bug?

Share this post


Link to post
Share on other sites
Check your pointers. In debug mode, all memory pointers are NULL'ed out, so if do any delete's or operation with them, then those instructions may be ignored. In release mode, they will be some random value and will be operated upon, thus causing a crash. Make sure you are initializing them all to NULL.

Next, narrow down where the bug is. As in comment everything out and see if it works. If it does, then start adding things back in slowly as execution will allow (i.e. don't allow deinit code and not init [wink]) and see if you can find it.

If it should happen to crash before that, make sure you are using the right runtimes for your projects and all your libraries are compatible. Check over .DLL's as well.

Good luck!

Share this post


Link to post
Share on other sites
If this is a linux/unix platform try enabling core dumps and examine one of those:

ulimit -c unlimited
gdb program core.file

That way you can see the state of the program when it crashed. Isn't debugging fun. :) Isn't gdb great :)... Weeeee.

Share this post


Link to post
Share on other sites
Well, I just commented out a bunch of my main function and it worked. Uncommented stuff one at a time until I'd uncommented all the stuff, and it still worked. Apparently my computer was just throwing a hissy fit.

Sometimes programming just makes me angry...

Share this post


Link to post
Share on other sites
Sounds like a timing dependent problem, assuming the execution path is the same in the compiler and compiled exe. I had a problem once where a thread in the compiled exe would shut down faster than when connected to the debugger, resulting in some nasty stuff.

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