Anyone experience physics locking up after body removal?

  ... the Physics Box2D Extension for AndEngine.

Anyone experience physics locking up after body removal?

Postby OzLark » Mon Apr 30, 2012 7:30 am

I've been using box2d with AE for some time now - I understand the flow control of the update thread, but it seems that if I delete bodies it will often hang on the next collision. I'm using GLES2.

I'm pretty sure I'm doing the deletion in a safe manner (though the evidence would suggest not :) )...

This is how I'm doing my deletion:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final Sprite sprite = spriteToBeDeleted;
  2. mEngine.runOnUpdateThread(new Runnable() {
  3.         @Override                                        
  4.         public void run() {                              
  5.                 deleteSprite(sprite);                        
  6.         }                                                
  7. });
  9. private void deleteSprite(Sprite s) {            
  10.         if (s != null) {                            
  11.                 UserData ud = (UserData) s.getUserData();
  12.                 deleteObjectByBody(s, ud.body);            
  13.         }                                            
  14. }
  16. private void deleteObjectByBody(final Sprite s, final Body b) {                                              
  17.         if (b != null && s != null) {
  18.                 final PhysicsConnector pc = mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(s);
  19.                 if (pc != null) {
  20.                         mPhysicsWorld.unregisterPhysicsConnector(pc);
  21.                 }
  23.                 b.setActive(false);
  24.                 mPhysicsWorld.destroyBody(b);
  25.                 s.detachSelf();
  26.         }
  27. }
Parsed in 0.033 seconds, using GeSHi

On the next collision this will sometimes cause the game to hang hard (back button doesn't even respond). I've ruled out it being caused by a collision handler by removing having none registered.

So I've resorted to just setting my bodies to inactive instead of deleting them and hope they get cleaned up when I dispose the physical world.

Any ideas?
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Return to Physics Box2D

Who is online

Users browsing this forum: No registered users and 10 guests