• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!

We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE. ### #ActualPatriarch K Posted 12 January 2013 - 08:02 PM I'm making a java game at the moment and when I happen to kill two enemies at the exactly same time then the game crashes. I suppose it's something with threads and serializable or something. But I don't know. I use the following code when I'm removing objects from the arrayList. The problem appears when I kill two enemies at EXACTLY the same time. Then it freezes and say: Exception in thread "Thread-3" java.lang.IllegalStateException at java.util.ArrayList$Itr.remove(Unknown Source)
at Main.checkCollisions(Main.java:168)
at Main.run(Main.java:400)

// Skott med fiende
Iterator<Bullet> b = bubblor.iterator();
while(b.hasNext()){
Iterator<Enemy> e = enemies.iterator();
Bullet bob = b.next();
while(e.hasNext()){

Enemy fof = e.next();
Rectangle r1 = fof.getBounds();
Rectangle r2 = bob.getBounds();
if(r1.intersects(r2) ){
b.remove();
e.remove();
} } }

### #4Patriarch K

Posted 12 January 2013 - 08:00 PM

I'm making a java game at the moment and when I happen to kill two enemies at the exactly same time then the game crashes. I suppose it's something with threads and serializable or something. But I don't know. I use the following code when I'm removing objects from the arrayList. The problem appears when I kill two enemies at EXACTLY the same time. Then it freezes and say:

at java.util.ArrayList\$Itr.remove(Unknown Source)
at Main.checkCollisions(Main.java:168)
at Main.run(Main.java:400)

Iterator<Bullet> b = bubblor.iterator();		while(b.hasNext()){			Iterator<Enemy> e = enemies.iterator();			Bullet bob = b.next();			while(e.hasNext()){				Enemy fof = e.next();				Rectangle r1 = fof.getBounds();				Rectangle r2 = bob.getBounds();				if(r1.intersects(r2) ){					b.remove();					e.remove();					}					}						}

### #3Patriarch K

Posted 12 January 2013 - 07:50 PM

I'm making a java game at the moment and when I happen to kill two enemies at the exactly same time then the game crashes. I suppose it's something with threads and serializable or something. But I don't know. I use the following code when I'm removing objects from the arrayList. The problem appears when I kill two enemies at EXACTLY the same time. Then it freezes and say something with concurrentModificationError or something. I don't remember:
Iterator<Bullet> b = bubblor.iterator();		while(b.hasNext()){			Iterator<Enemy> e = enemies.iterator();			Bullet bob = b.next();			while(e.hasNext()){				Enemy fof = e.next();				Rectangle r1 = fof.getBounds();				Rectangle r2 = bob.getBounds();				if(r1.intersects(r2) ){					b.remove();					e.remove();					}					}						}

### #2Patriarch K

Posted 12 January 2013 - 07:50 PM

I'm making a java game at the moment and when I happen to kill two enemies at the exactly same time then the game crashes. I suppose it's something with threads and serializable or something. But I don't know. I use the following code when I'm removing objects from the arrayList. The problem appears when I kill two enemies at EXACTLY the same time. Then it freezes and say something with concurrentModificationError or something. I don't remember:
Iterator<Bullet> b = bubblor.iterator();		while(b.hasNext()){			Iterator<Enemy> e = enemies.iterator();			Bullet bob = b.next();			while(e.hasNext()){				Enemy fof = e.next();				Rectangle r1 = fof.getBounds();				Rectangle r2 = bob.getBounds();				if(r1.intersects(r2) ){					b.remove();					e.remove();					}					}						}

### #1Patriarch K

Posted 12 January 2013 - 07:41 PM

I'm making a java game at the moment and when I happen to kill two enemies at the exactly same time then the game crashes. I suppose it's something with threads and serializable or something. But I don't know. I use the following code when I'm removing objects from the arrayList:


Iterator<Bullet> b = bubblor.iterator();
while(b.hasNext()){
Iterator<Enemy> e = enemies.iterator();
Bullet bob = b.next();
while(e.hasNext()){

Enemy fof = e.next();
Rectangle r1 = fof.getBounds();
Rectangle r2 = bob.getBounds();
if(r1.intersects(r2) ){
b.remove();
e.remove();
}
}
}


PARTNERS