I have an SWR based MUD that I started with using SWRFUSS 1.0. I have applied all of the bug fixes from the SmaugMuds.org SWR forum list so hopefully I am up-to-date and didn't miss any. However, I am having a weird issue I can't seem to figure out or track down exactly why it's causing a crash. I have not done anything to the way corpses are created. I've also compared my code to SWRFUSS 1.2 and 1.3 code and it all looks the same.
Here is the situation:
Mob has nocorpse flag. Kill mob, MUD crashes.
GDB returns this information:
(gdb) bt #0 0x00000000005227bc in damage (ch=0x1998a80, victim=0x0, dam=439, dt=1006) at fight.c:2032 #1 0x00000000005201e6 in one_hit (ch=0x1998a80, victim=0x17c3760, dt=1006) at fight.c:1402 #2 0x000000000051d496 in multi_hit (ch=0x1998a80, victim=0x17c3760, dt=-1) at fight.c:501 #3 0x0000000000526d5f in do_kill (ch=0x1998a80, argument=0x7fff196682d5 "toodan") at fight.c:3413 #4 0x000000000054df8b in interpret (ch=0x1998a80, argument=0x7fff196682d5 "toodan") at interp.c:412 #5 0x00000000004e1e83 in game_loop () at comm.c:730 #6 0x00000000004e0d1f in main (argc=6, argv=0x7fff19668828) at comm.c:304 (gdb)
At a quick glance the only thing that jumps out at me is this:
#0 0x00000000005227bc in damage (ch=0x1998a80, victim=0x0, dam=439, dt=1006) at fight.c:2032
You don't seem to have a victim pointer anymore. The other lines are this: victim=0x17c3760.
That's probably the cause. Go to 'frame 1' and 'l' to figure out why your victim pointer becomes NULL. Maybe you shouldn't even reach do_damage in this case…
About the only thing in the line that crashed that could cause it, is new_corpse being a bad (and not NULL) pointer. Taking a look at the smaugfuss 1.3 code in the raw_kill function, it does seem this can happen, as the corpse_to_return variable is not initialized, and is just returned in the case where no corpse is created. I would change the line in raw_kill (near the top of the function) from:
OBJ_DATA *corpse_to_return;
to:
OBJ_DATA *corpse_to_return = NULL;
As to the victim issue, I would be concerned if victim was NOT NULL at this point. Victim is NULL as it was set so in line 2030 (line 5 listed in the OP).
Initially I looked through the other versions of SWR to see if I could see any differences between my code and the newer SWRFUSS codes. I didn't notice anything different in the way corpses are created or how damaging a mob took place. I did find some changes in the SWFotE code that used an integer called nocorpse and it was set to TRUE if the mob had the nocorpse flag. This integer was then used in an ifcheck for checking whether or not a player would autoloot the corpse or look in the corpse. This solved the issue, but I am not sure if its safe enough to trust.
Sharmair's simple fix seems to be the safest way to prevent a crash with a nocorpse flag. I have confirmed that it works.
Here is the situation:
Mob has nocorpse flag.
Kill mob, MUD crashes.
GDB returns this information:
*Toodan is just the name of the mob.
Before I posted this, I went back to check other corpse affecting flags for mobs, ie. NOKILL, and it worked properly.
Any help would be appreciated. Thanks.