Fix concurrent modification exception on attempt to remove entity inside for-each-entity loop

This commit is contained in:
2022-08-25 14:01:17 +02:00
parent 23738566e3
commit 9e416655e7

View File

@@ -59,7 +59,11 @@ public class DefaultObjectLayer extends BaseLayer implements ObjectLayer {
@Override
public void removeEntity(Entity entity) {
entities.remove(entity);
// Disclaimer
// This is a workaround for concurrent modification exception
// which is thrown when entity is tried to be removed
// in the body of for-each-entity loop
entities.remove(entities.indexOf(entity));
entity.onRemove(this);
}