So i recently dug out some old Games, and one of it was Operation: InnerSpace. Since it won't run on Windows 7 and lags horribly in VirualPC I tried to make something similar in Processing. But I've encountered a problem.
I'm storing Bullets and Enemies and that stuff in ArrayLists, and when they are removed from the list I alway get java.util.ConcurrentModificationException. I think it is because the functions in the draw loop try to access stuff that is currently being changed by the GameLogic thread, but I can't find a way to avoid it. Currently i just catch the exceptions, but that causes stuff to to disappear for one frame when the exception is thrown.
I already tried to put a boolean in the thread that goes true if the thread is working and stops the execution of the draw loop until it is finished, but it didn't help.
Could somebody please help me with this?
Draw Loop:
void draw() {
background(bg);
void drawBullets() {
try {
for (Bullet b: bullets) {
b.disp();
}
} catch(Exception e) {
println("Bullet: " + e);
}
}
...
// other stuff goes here...
}
Game Logic thread:
void gameLogic() {
...
// keyboard control stuff...
...
ArrayList<Bullet> bulletsToDelete = new ArrayList<Bullet>();