C++ – Debugging a crash after exiting? (After main returned)

cdebuggingmultithreadingvisual c++windows-vista

This is a fairly involved bug, and I've tried looking around to find other sources of help, but for reasons I don't understand, "Program Crashes in Vista" is not the most helpful query.

The issue I'm having is that the program I'm working on – a graphical, multithreaded data visualization software that uses OpenGL and the Windows API – is crashing after WinMain() returns. I've tried stepping through the shutdown routine as well as looking at a stack trace, and the last bit of code that's not assembly is _crtExitProcess, where it crashes in the actual ExitProcess(0) call. After that, the stack trace shows kernel32.dll and four ntdll.dll, which is where it actually crashes.

This bug only occurs on Vista, and the same exact code when run on XP exits normally. I really can't think of anything that would help me debug this problem, and debugging this issue is something I've never really learned. Any help would be appreciated.

Best Answer

I've done a little digging around, and I've found a couple of posts around that suggest you're not the only one suffering from this:

Particularly, the second one is of interest, where Tom Chm mentions:

We believe we have identified the root cause of our crash, and adding a virtual destructor to our interface class wrapper seems to resolve our problem. But we would like to know the exact cause of the crash to verify that we didn't just sweep the actual problem under the rug.

The problem may be with a destructor somewhere, or lack thereof. If you have a way of attaching a debugger and stepping through the shutdown process, it might be of help.

You might want to read through the whole thread and see if there's something you can learn. That is, if you haven't already found these posts in your searching, of course.