(svn r11497) [NoAI] -Fix: when removing the last item from a bucket, the bucket gets removed invalidating iterators. Based on a patch by xargonax.
--- a/src/ai/api/ai_abstractlist.cpp Thu Nov 22 23:00:00 2007 +0000
+++ b/src/ai/api/ai_abstractlist.cpp Thu Nov 22 23:01:41 2007 +0000
@@ -415,7 +415,14 @@
for (AIItemList::reverse_iterator next_iter, iter = items->rbegin(); iter != items->rend(); iter = next_iter) {
if (--count < 0) return;
next_iter = iter; next_iter++;
+ /*
+ * When the last item is removed from the bucket, the bucket itself
+ * is also removed in MSVC. This means that the iterators can be
+ * invalid after a call to RemoveItem.
+ */
+ bool bucket_empty = next_iter == items->rend();
this->RemoveItem(*iter);
+ if (bucket_empty) break;
}
}