On Thu, Sep 19, 2002 at 01:54:34PM -0700, Matt Foltz wrote:
> A builder on my mud is making an area full of land
> mines.  When a mob walks across a land mine, it
> triggers a program to make an asound and purge the
> mobs in the room.  Problem is that I get these errors
> in the log files:
> 
> BUG: Char_from_room: ch not found
> BUG: Extract_char: ch not found
> 
> The first error puts all players into some weird
> state, where they don't receive any messages that
> require a descriptor lookup (possibly them simulate a
> non-switched NPC, basically).  The second error flat
> out crashed the mud.  I haven't changed mppurge,
> char_from_room, or extract_char from how the
> stock/patch is.  Has anyone seen this before?

This is a logic bug.  Without seeing your code, it is impossible to say
how to fix it.  I can explain the problem in general terms and the
general solution to it, though:

In C, you have something like the following:

    for ( victim = ch->in_room->people; victim ; victim = victim->next_in_room )
    {
        if (IS_NPC(victim))
            extract_char(victim, TRUE);
    }

The problem is that when you extract that first character, the
next_in_room pointer is now f'd up.  This is bad, since it no longer
points to who the next person was in the room before you toasted that
one.

The solution?  A temporary variable.

    for ( victim = ch->in_room->people; victim ; victim = v_next )
    {
        v_next = victim->next_in_room;
        if (IS_NPC(victim))
            extract_char(victim, TRUE);
    }

You will see this sort of construct all over ROM.  Grep for '_next' for
examples.

How you fix your case would, again, depend on the code.


Reply via email to