Hello again,
I've been playing around with processing, and I'm really enjoying it. I am creating a few collision detection program and I'm having some problems. Here's what I do:
1. every second I create a Boid (object1) and add it to the boids ArrayList (max 20 boids)
2. every 3 seconds I create an AntiBoid (object2).and add it to the Antiboid ArrayList (max 3 antiboids)
3. they move randomly on screen, and when a boid collides with antiboid, I delete the boid from the array list.
when doing so, I randomly get a crash when adding a new boid, always the same problem: (I will not paste the full dump, don't worry )
I've been playing around with processing, and I'm really enjoying it. I am creating a few collision detection program and I'm having some problems. Here's what I do:
1. every second I create a Boid (object1) and add it to the boids ArrayList (max 20 boids)
2. every 3 seconds I create an AntiBoid (object2).and add it to the Antiboid ArrayList (max 3 antiboids)
3. they move randomly on screen, and when a boid collides with antiboid, I delete the boid from the array list.
when doing so, I randomly get a crash when adding a new boid, always the same problem: (I will not paste the full dump, don't worry )
- j com.sun.opengl.impl.GLImpl.glDeleteTextures1(ILjava/lang/Object;I)V+0
- j com.sun.opengl.impl.GLImpl.glDeleteTextures(I[II)V+64
- j codeanticode.glgraphics.GLTexture.releaseTexture()V+10
- j codeanticode.glgraphics.GLTexture.finalize()V+10
- //Draw boid!
- println("Draw boid " + wanderers.size());
- for (int n = 0; n < wanderers.size(); n++) {
- Boid wanderBoid = (Boid)wanderers.get(n);
- if (dist(mouseX, mouseY, wanderBoid.location.x, wanderBoid.location.y) <= 100) {
- wanderBoid.timeCount = 0;
- wanderBoid.evade(new PVector(mouseX, mouseY));
- }
- else {
- wanderBoid.wander();
- }
- offscreen.beginDraw();
- offscreen.beginGL();
- wanderBoid.run(gl);
- offscreen.endGL();
- offscreen.endDraw();
- }
- println("Draw antiboid water");
- //Draw antiboid and calculate collissions.
- for (int n = 0; n < antiboids.size(); n++) {
- antiboid antiboid = (antiboid)antiboids.get(n);
- boolean delete = false;
- //check collision with boid!
- for (int b = 0; b < wanderers.size(); b++) {
- Boid wanderBoid = (Boid)wanderers.get(b);
- if (dist(antiboid._position.x, antiboid._position.y, wanderBoid.location.x, wanderBoid.location.y) <= 100) {
- //delete boid!!!!
- wanderers.remove(b);
- addboidCounter--;
- println("boid deleted " + wanderers.size());
- }
- }
- offscreen.beginDraw();
- offscreen.beginGL();
- antiboid.drawWater(gl);
- offscreen.endGL();
- offscreen.endDraw();
- }
- println(wanderers.size());
- ...
- //add new boid?
- if (millis() > lastBirthTimecheck + 1000) {
- lastBirthTimecheck = millis();
- if (addboidCounter < NUM_BOIDS) addboid((int)random(-10, width + 10), (int)random(-10, height +10));
- }
- //add new antiboid?
- if(((millis() > lastantiboidThrown + 5000 && antiboids.size() == 0) || (millis() > lastantiboidThrown + 3000 && antiboids.size() > 0)) && NUM_antiboidES > antiboids.size())
- {
- antiboids.add(new antiboid("bag", 125, new PVector(0, random(100,300)), 5, new PVector(5,5), 100, this));
- println("antiboid " + antiboids.size() + " Added");
- }
- offscreen.beginDraw();
- offscreen.beginGL();
- ...
- offscreen.endGL();
- offscreen.endDraw();
1