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:
Using java Syntax Highlighting
- final Sprite sprite = spriteToBeDeleted;
- mEngine.runOnUpdateThread(new Runnable() {
- @Override
- public void run() {
- deleteSprite(sprite);
- }
- });
- private void deleteSprite(Sprite s) {
- if (s != null) {
- UserData ud = (UserData) s.getUserData();
- deleteObjectByBody(s, ud.body);
- }
- }
- private void deleteObjectByBody(final Sprite s, final Body b) {
- if (b != null && s != null) {
- final PhysicsConnector pc = mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(s);
- if (pc != null) {
- mPhysicsWorld.unregisterPhysicsConnector(pc);
- }
- b.setActive(false);
- mPhysicsWorld.destroyBody(b);
- s.detachSelf();
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
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?
