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
body != null
in the inner if statement when it is first used in your first if statementbody.getUserData() != null
. Second, what doesmWorld.destroyBody( body );
do? Do you have any other threads running? \$\endgroup\$