Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when clearing points with bodies in world #29

Open
GoogleCodeExporter opened this issue Mar 7, 2016 · 0 comments
Open

NPE when clearing points with bodies in world #29

GoogleCodeExporter opened this issue Mar 7, 2016 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant