Errors happen when using World.destroyBody( Body body )

Posted by minami on Game Development See other posts from Game Development or by minami
Published on 2012-03-02T09:12:17Z Indexed on 2012/06/04 10:51 UTC
Read the original article Hit count: 290

Filed under:
|
|

on Android application using libgdx, when I use World.destroyBody( Body body ) method, once in a while the application suddenly shuts down.

Is there some setting I need to do with body collision or Box2DDebugRenderer before I destroy bodies?

Below is the source I use for destroying bodies.

private void deleteUnusedObject( ) {
    for( Iterator<Body> iter = mWorld.getBodies() ; iter.hasNext() ; ){
        Body body = iter.next( ) ;
        if( body.getUserData( ) != null ) {
            Box2DUserData data = (Box2DUserData) body.getUserData( ) ;
            if( ! data.getActFlag() ) {
                if( body != null ) {
                    mWorld.destroyBody( body ) ;
                }
            }
        }
    }
}

Thanks

© Game Development or respective owner

Related posts about box2d

Related posts about libgdx