Hey I have another problem now. Can you tell me why this happens?
i have a class that looks like this:
public class Pellet extends Object3D implements Runnable{
Shoot shoot;
public Pellet(SimpleVector direction){
super(Primitives.getSphere(2f));
shoot = new Shoot(this, direction);
}
public void run() {
shoot.start();
}
private class Shoot extends Thread{
SimpleVector direction;
Pellet pellet;
float speed = 10;//speed of bullet
int time = 15; //time bullet exists
Shoot(Pellet pellet, SimpleVector direction){
this.direction = direction;
this.pellet = pellet;
}
@Override
public void run(){
int count = time;
direction.scalarMul(speed);
while(count > 0){
try {
sleep(100);
pellet.translate(direction);
count--;
} catch (InterruptedException ex) {
Logger.getLogger(Pellet.class.getName()).log(Level.SEVERE, null, ex);
}
}
Main.world.removeObject(pellet);
}
}
}
and implement it like this:
case (Keyboard.KEY_LCONTROL) :{
if(event == KeyState.PRESSED){
combat.Pellet pellet = new combat.Pellet(model.getXAxis());
pellet.setOrigin(model.getTransformedCenter());
world.addObject(pellet);
pellet.build();
pellet.run();
}
}
It basically creates a sphere where the player is standing and it shoots forward and then dissapears after awhile.
at first it seems to work fine but if you spam it really fast at some point it causes a null pointer exception at com.threed.jpct.World.renderScene(Unknown Source).
However, this null pointer exception does not happen if I remove the Main.world.removeObject(pellet) from the Pellet class, in other words I don't get the error if I keep the sphere on the world. Is this because I'm doing these changes to this object outside of the main Thread again? How can I make something keep moving outside of the main thread?
Here is a link to the program again:
http://www.sendspace.com/file/77n790Thanks.