Fix concurrent modification exception on attempt to remove entity inside for-each-entity loop
This commit is contained in:
@@ -59,7 +59,11 @@ public class DefaultObjectLayer extends BaseLayer implements ObjectLayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeEntity(Entity entity) {
|
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);
|
entity.onRemove(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user