DebuggingCrashes

From TTWiki
Jump to: navigation, search

When TTDPatch or TTD crash without producing a crash log file (crash###.txt), it is very hard for the developers to figure out what went wrong or how to fix it. The same applies for when TTD stops responding and hangs, so that you have to kill it with the task manager.

If a crash log is produced, simply forward it to the patch developers. This document explains how to get the information that's usually in the crash log to the patch developers so they may attempt to figure out what the problem is in the absence of a crash log.

The process to get this information uses a debugger, a program that can catch crashes and interrupt a hung process in a controlled manner. If you've never used a debugger before, don't worry, we have step-by-step instructions here to tell you how to use it.

If you need help at any time, the best choice is to visit the #tycoon IRC channel, or use the chat applet on TT-Forums. There's usually a patch developer there who can help you.

Install a debugger

First you need to install a debugger, if you don't have it already. Download OllyDbg and install it.

Run it once, and open the "Debugging options" dialog.

Options.png

Now open the "Exceptions" tab, and check the "Integer division by 0" and "All FPU exceptions" boxes.

Options2.png

Click "OK" and quit. OllyDbg is now set up properly for debugging TTD/TTDPatch.

Debugging a crash

If the game crashes, but does not create a crash log, you need to have the debugger catch the crash. There are two possible ways of doing this. If the crash happens before you get to the TTD title screen, or if the following instructions do not work or do not catch the crash, try those in the next section below.

This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would crash anyway so that's no different to what you had before).

  • Start TTD normally
  • When TTD shows the title screen, press Alt-Tab or Alt-Esc to return to Windows
  • Start OllyDbg
  • Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"
Attach.png
  • You will now get an "Entry point alert" warning. Simply click "OK".
  • Continue to run TTD by pressing the "F9" key or clicking the "run" button Runbutton.png.
  • Now return to TTD in the task bar or with Alt-Tab
  • Reproduce the steps that caused the crash last time
  • At the time of the crash, OllyDbg should start flashing in the task bar
  • Click on it there to bring up the window, maximize OllyDbg, and take a screenshot

Submit this screenshot to the patch developers. It is best to go to the #tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD.

Debugging a crash (alternate)

If the above instructions don't catch the crash, especially if the crash happens before the title window comes up, try this method.

First, open your ttdpatch.cfg in Notepad, and enter the following line somewhere:

debugswitches r

With this, TTD/TTDPatch will no longer start up normally, so be sure to remove it again when you're done with this procedure.

Now start TTDPatch. It will do the normal steps and then show the following warning:

Couldn't execute TTDLOADW.OVL: DEBUG SWITCH

At this point, start OllyDbg. Select File|Open, browse to your TTD folder, and open TTDLOADW.OVL.

  • You will now get an "Entry point alert" warning. Simply click "OK".
  • Now press F9 or the "run" button Runbutton.png to start TTDPatch and TTD.
  • Reproduce the steps that caused the crash last time
  • At the time of the crash, OllyDbg should start flashing in the task bar
  • Click on it there to bring up the window, maximize OllyDbg, and take a screenshot

Submit this screenshot to the patch developers. It is best to go to the #tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD. Press any key in the TTDPatch window to close it as well.

Debugging a hang

Follow this procedure if TTD stops responding for a long time. This requires that you can Alt-Tab or Alt-Esc out of TTD back to Windows. If you can't Alt-Tab out, try running TTD in windowed mode. Note that you will not be able to save your game when it happens (but it would hang anyway so that's no different to what you had before).

  • Reproduce what you were doing when TTD stopped responding
  • When TTD stops responding again, press Alt-Tab or Alt-Esc to return to Windows
  • Start OllyDbg
  • Select File|Attach, then choose "Transport Tycoon Deluxe" (it should have TTDLOADW.OVL in the name and path columns), then click "Attach"

Attach.png

You will now get an "Entry point alert" warning. Simply click "OK". At this point the window should look like this (click on thumbnail for full size view):

Postattach.png

Note the "EIP" line on the right. After 8 hex digits, it will say something with either "NTDLL" or "KERNEL32", depending on your Windows version. If it doesn't, ask for help at this point.

Now select "Debug|Execute till user code" or press Alt-F9, and check the EIP line again. It should say "TTDLOADW" after the 8 hex digits:

Ttdloadw.png

Note that the letters/digits don't matter, just check that it says TTDLOADW. If it doesn't, something is probably not working, so ask for help at this point.

At this point, take a screenshot of the entire OllyDbg window and submit it to the patch developers. It is best to go to the tycoon IRC channel or the forum chat applet right away, with the windows still open, to see if the patch developers need any further information at this point.

When done, simply close OllyDbg. This will also close TTD.

Final notes

  1. When using OllyDbg to debug crashes or hangs, it is very much advisable, although not absolutely required, to start TTD in windowed mode, not full-screen mode.
  2. For unknown reasons, OllyDbg sometimes fails to provide us as much information as we would like. Sometimes, the screenshot will look like this (click on thumbnail for full size view):
Debug1.png
(It doesn't matter which letters/digits appear in the "Same number" area, but it will be the same set on every line, and all three areas marked "Empty" will be.)

If this happens, something went wrong with OllyDbg. Submit the screenshot as normal, but then please contact Yuschuk, and tell him you can reproduce the problem DaleStan reported. Please do everything he asks of you, so this issue may be resolved as quickly as possible.