MovingBlocks / box2d-editor

Automatically exported from code.google.com/p/box2d-editor - migrated here to maybe maintain together with Destination Sol. Original website:
https://code.google.com/archive/p/box2d-editor/
Apache License 2.0
84 stars 21 forks source link

NPE when clearing points with bodies in world #29

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.badlogic.gdx.physics.box2d.World.destroyBody(World.java:309)
    at aurelienribon.bodyeditor.canvas.rigidbodies.RigidBodiesScreen.clearWorld(Unknown Source)
    at aurelienribon.bodyeditor.canvas.rigidbodies.RigidBodiesScreen.access$300(Unknown Source)

In RigidBodiesStream:

Iterator<Body> bodies = world.getBodies();
while (bodies.hasNext()) world.destroyBody(bodies.next());

This look suspicious; are you sure the iterator's backing collection isn't 
modified?

A conservative approach:

boolean empty = false;
while (!empty) {
  Iterator<Body> bodies = world.getBodies();
  empty = !bodies.hasNext();
  if (!empty) {
    world.destroyBody(bodies.next());
  }
}

Original issue reported on code.google.com by ernest.m...@gmail.com on 20 Mar 2014 at 3:00

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29226596-npe-when-clearing-points-with-bodies-in-world?utm_campaign=plugin&utm_content=tracker%2F23699865&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F23699865&utm_medium=issues&utm_source=github).