Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#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)
at java.lang.Thread.run(Unknown Source)



// 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:

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)
at java.lang.Thread.run(Unknown Source)



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