Trying to understand why I can't create a new object. I have one spawning object that comes up slowly and once it is done with frame 5 it is supposed to spawn a new object and die. It is throwing a java.util.ConcurrentModificationException and I looked it up but don't understand it. I thought maybe it was calling too many chickens so I did try to create a function to call it from a different class. When called from the other class it made it one line more. It said the string but then got hung on the same exception.
@Override
public void die() {
//this is set up to find the last animation frame
float x = location.getX();
float y = location.getY();
int orient = orientation;
if(animSpawnRight.getIndex() == 4){
//spawn chicken
//then die
handler.getWorld().getChickenSpawner().setHoleFalse(location);
//executes to here and doesn't read string
System.out.print("ARG CHICKENS not working!" + x + " , " + y + " , " + orientation);
handler.getWorld().getEntityManager().addEntity(new Chicken(handler, x, y, orientation));
super.setActive(false);
}
}
The error log brings me to my Entity Manager:
public void tick(){
Iterator<Entity> it = entities.iterator();
while(it.hasNext()){
Entity e = it.next();
e.tick();
if(!e.isActive())
//it.remove() below is the problem
it.remove();
}
entities.sort(renderSorter);
}
Goal: ChickenSpawner, which basically watches a timer, spawns a chickenspawning object. ChickenSpawning object plays a short animation and then calls a new chicken. (The spawningChicken and Chicken object were separated because it was easier to make sure you can't shoot it early.
(I even tried commenting out: super.setActive(false); but that didn't work either). Is it calling too many chickens? and If so how do I get it to call only one? I have struggled a bit with multithreading.
EDIT e.tick() calls the classes tick for all "entities" that the entity manager is holding.
And I forgot I put die() in chickenSpawning for some reason - probably a super lazy way to see the chickenspawning animation before finishing how it connected to everything.
@Override
public void tick() {
animSpawnUp.tick();
animSpawnDown.tick();
animSpawnLeft.tick();
animSpawnRight.tick();
die();
}
So is it deleting and existing at the same time?