(svn r11497) [NoAI] -Fix: when removing the last item from a bucket, the bucket gets removed invalidating iterators. Based on a patch by xargonax. noai
authorrubidium
Thu, 22 Nov 2007 23:01:41 +0000
branchnoai
changeset 9721 9a27928bcd5e
parent 9720 2b1f99d52a7b
child 9722 ebf0ece7d8f6
(svn r11497) [NoAI] -Fix: when removing the last item from a bucket, the bucket gets removed invalidating iterators. Based on a patch by xargonax.
src/ai/api/ai_abstractlist.cpp
--- 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;
 				}
 			}