[Followup] ch->next == ch... but not possible!

From: Chris Jacobson (fear@ATHENET.NET)
Date: 12/01/97

On 12/1/97 3:10 AM, Chris Jacobson (fear@athenet.net) stated:

>I'm having WIERD errors after I did a major upgrade of my code.
>The basics of the problem is this:
>the character  is being removed from the character_list, flagged
>"purged", and put into another list.
>A loop later on runs through character_list, and lo and behold, that
>character is STILL in character_list, flagged "purged", AND points back
>to itself.
>I searched for EVERY occurance of "next" in the source, scanned them over
>three times to make sure there was no wierd source error...
>Made it log when it was marking characters "purged" and when it
>encounters characters marked "purged" but it shouldn't.
>Made it even make sure it was finding the character in character_list,
>then ALSO making sure it wasn't finding it a second time (i.e, that it
>might be in the list twice).
>So its wierd... very wierd.  Im wondering, has anyone ever had a problem
>of ch->next == ch, and what did you notice was causing the problem?

Ok I don't know how ch->next =='d ch, but the probs are gone.
My main problem was also the disappearance/reappearance in
character_list, and it was in mob_act.

Well, because a character can get purged in mob_act, it sets next_ch to
ch->next right away.  What was happening was ch->next was actually
getting extracted (and removed from character_list) right away in ch's
events.  This caused the program to stop on my OTHER catches, and made it
appear to be in the list.  Usign some logging and %x's (aren't they
wonderful :-) I realized that next_ch was pointing to a possibly purged
character, and so made a new variable, prev, that was set in the for
loop.  Now it looks like:

        for (ch = character_list, i = 1, prev = NULL; ch; prev = ch, ch =
next_ch, i++) {
                next_ch = ch->next;

                if (prev && (prev->next != ch))
                        ch = prev->next;

                if (!ch)

Well, that solved my problems...

- Chris Jacobson

PS. I ported over several of Death's Gate (Circle based, C++) features to
my own MUD (which is still plain C, Im staying away from C++).  The
features include: the script system (very powerful, and basically
crashproof), a few minor enhancements, and the non-immediate extraction
(anything extracted isn't free'd until game_loop).

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |

This archive was generated by hypermail 2b30 : 12/08/00 PST