From 1cf51aae80055e5fb9b60a1bcd8a55f65d062ca2 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 5 Jul 2023 13:29:51 +0100 Subject: Avoid iterator invalidation issues in ActionList::Run. --- src/cull.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/cull.cpp') diff --git a/src/cull.cpp b/src/cull.cpp index 4957773e2..b2cf536a5 100644 --- a/src/cull.cpp +++ b/src/cull.cpp @@ -127,7 +127,9 @@ void CullList::Apply() void ActionList::Run() { - for (auto* action : list) - action->Call(); + // IMPORTANT: we can't use a range-based for loop here as adding to the list + // may invalidate the list iterators. + for (size_t idx = 0; idx < list.size(); ++idx) + list[idx]->Call(); list.clear(); } -- cgit v1.3.1-10-gc9f91