What if you just use a for loop instead, and check for null objects? Would that not (although while being a cheap solution), stop throwing you those exceptions?
@sproingie
Arh, well, I am synch’ing it myself But I’ll make a note to remember to not mix concurrent collections and internally-synch’ed methods.
@Mads
It’s not null pointers that’s causing that exception. It’s because elements are being added or removed from the list while it’s being iterated through.
He means a for-loop with an index and a getter. The CME is only thrown when using for(x:y) loops or Iterators. So his suggestion is
for(int i=0; i<entitiesToTick.size(); i++)
{
Entity e=entitiesToTick.get(i);
if(e!=null) e.tick();
}
unfortunately that won’t work either, because of:
so if an element gets removed while iterating over it, an IOOBE is thrown. Other than that, this loop could lead to missed entities or double calls to tick() on the same entity.