View Full Version : 'nother TFork segfault

Therem Harth
October 18, 2010, 05:29
This time on making a wish for something that doesn't exist in the game. Which is weird because I haven't messed with the wish code at all.

Basically if you wish for "foo" or some other thing that isn't an item or a monster, the game will spit out a Lua error about doing get_stick_charges on a nil value, followed by a crash. The backtrace looks like this:

#0 object_desc_str (t=0xbffff054 "", s=0x0) at object1.c:1262
#1 0x0810c54e in object_desc (buf=0xbffff178 "wand of poison blood",
o_ptr=0xbffff2b0, pref=0, mode=0) at object1.c:2059
#2 0x08136a2a in test_object_wish (name=0xbffff330 "foo", o_ptr=0xbffff2b0,
forge=0xbffff2b0, what=0x81ea03f "wish") at xtra2.c:7411
#3 0x08136dde in make_wish () at xtra2.c:7570
#4 0x081c04aa in do_cmd_debug () at wizard2.c:1912
#5 0x080ec59e in process_command () at dungeon.c:3558
#6 0x080f159e in process_player () at dungeon.c:4875
#7 0x080f2296 in dungeon (new_game=<value optimized out>) at dungeon.c:5327
#8 play_game (new_game=<value optimized out>) at dungeon.c:5816
#9 0x081dea5c in main (argc=1, argv=<value optimized out>) at main.c:908

I did try doing a check for NULL before object1.c line 1262... That prevents the crash, but I still get an unsightly Lua error, which I'm guessing indicates that that wasn't the actual bug.

(Any help would be appreciated, I'm terribly lame with dealing with strings in C.)

Edit: and yeah I realize it's probably a bad sign when altering one part of a codebase causes a completely unrelated part to throw an error. :)

Pete Mack
October 23, 2010, 03:58
You are out of luck if you don't have a real debugger.
You should be running your app from within the debugger, always.
If you are not on Windows, use GDB. (I've had terrible luck with GDB on Windows.)
If you are on Windows, download Visual Studio Express if you have enough memory. (Visual Studio is a notorious memory hog.) You will have to set up a project, which takes a couple hours. But having a debugger with break points makes it so worth it.

October 23, 2010, 07:07
If you need a debugger for a unix-like system, you can also use DDD. It's a graphical front-end for GDB. It's been ages since I actually used it, but I remember it as being excellent (at the time).

October 23, 2010, 07:56
If the error is in Lua a debugger won't help much*. You'll need to resort to gratuitous print statement debugging.

* until you get your next error and it's in the C.

Therem Harth
October 23, 2010, 15:26
I was using GDB... What I posted was GDB's backtrace.

For the record, the problem turned out to be a pretty weird one - some schools cannot have their spells altered in any way, otherwise the game will crash. Air school is one of those schools, and I'd made modifications to it.

I'm still trying to figure out why this is; I would guess some of Air's attributes are hard-coded in a way not conducive to just changing the Lua code. I tried removing some of the wands for that school, but that didn't work at all... But anyway it's fixed now in Git, though I'm not happy with Air school still being mostly useless.