Hunting a magic bug

Started by
3 comments, last by Structural 18 years, 10 months ago
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?
Advertisement
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!
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.
It is foolish for a wise man to be silent, but wise for a fool.
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...
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.
STOP THE PLANET!! I WANT TO GET OFF!!

This topic is closed to new replies.

Advertisement