mattgodbolt / xania

Xania MUD source
Other
58 stars 13 forks source link

Issues with iterating over lists that are mutated as we go (specifically pets) #182

Closed mattgodbolt closed 4 years ago

mattgodbolt commented 4 years ago

There's a lot of code that loops over CHAR_DATAs in various containers with code like:

for (auto *ch = blah; ch; ch = ch->next) {...}

Some code takes defensive action "what if the the ch is removed/deleted/moved...

CHAR_DATA *ch_next;
for (auto *ch = blah; ch; ch = ch_next) {
 ch_next = ch->next;
 ...maybe do stuff that deletes `ch` or moves it out of the room or whatever...
}

This is "ok" but:

In the first case, some smart iteration will make this "go away" (mostly).

In the second case, smart iteration may be able to be taught (I have ideas)...

The second case can probably happen when: