Array has changed during ranged-for iteration

anonymous_user_08c2fdfc
Thu, 14 Apr 2016 07:57:23 +0000
Audio

I upgraded to 4.11 and now I have the following error:

Array has changed during ranged-for
iteration

This happens because I add some elements in my TArray while iterating over it. I am aware of what I am doing, the elements I add in the array should be processed in the same for loop.

TArray<FEdge*> Edges;
// [...] Fill Edges
for(FEdge* Edge:Edges)
{
   Process(Edge);
   if(Condition(Edge))
   {
       Edges.Add(new FEdge());    // Add a new edge to be processed later
   }
}

What is the prefered method of doing so? Using a while loop?

7 posts - 3 participants