Previous  Top  Next

Debugging Crashes

The absolute first thing to do when debugging crashes is to attach a debugger. As silly as it sounds, most of you reading this probably didn't even consider it. In MS Visual Studio, pull down Debug and hit Processes.. Then double click on eqgame.exe assuming you have it running. Leave "Native" selected in the program types box and just hit OK. Close the process list box and you're done with that. If you open the output window (CTRL+ALT+O) in VS, you can see the DebugSpew. Go make it crash, and hopefully it will break into the debugger and show you the line that it broke on.

Often it's difficult for you to figure out what's going on, since it may crash inside EQ and not be able to show you the line that broke. If this is directly caused by your code and you cannot determine the line that's crashing, MQ2 provides a way for you to debug this. Place DebugTry(whatever); around each line of code you think may be crashing. For example, if a line of code says "pTarget->Something(x);" you can make it "DebugTry(pTarget->Something(x));". DebugTry is something you must turn on for it to do anything at all. If it's not turned on, nothing extra at all is added to the compiled output. To turn it on, you need to "#define DEBUG_TRY 1" before MQ2Main.h is included. If you are working within a plugin, you need to do the define before "../MQ2Plugin.h" is included. What DebugTry will do is output some DebugSpew directly before and after the code that gets executed. By looking at the resulting debug spew, you can determine exactly which line is causing the problem. Fix that line and you have solved the current problem. Then you can disable DEBUG_TRY and have the choice of removing the DebugTry() around your lines of code or leaving it there. Again, if you leave it there and do not turn on DEBUG_TRY, it will do absolutely nothing to the compiled output.