Removing a body does not remove it from mBodiesByName (java)

Report problems here (or use the built-in feedback dialog in the editor)
Post Reply
notnowlewis
Posts: 8
Joined: Tue Jul 09, 2013 6:46 pm

Removing a body does not remove it from mBodiesByName (java)

Post by notnowlewis » Mon Aug 26, 2013 7:02 pm

This seems pretty simple to reproduce:

Code: Select all

scene.putNamed("mybody", myBody);
System.println.out(scene.getNamed(Body.class, "mybody").size); // 1
scene.getWorld.destroyBody(myBody);
System.println.out(scene.getNamed(Body.class, "mybody").size); // should be 0, is still 1
This has driven me half crazy today trying to figure out why I'm getting more bodies back than i should! But there's nothing to remove an entry from mBodiesByName, only to add to it.

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Removing a body does not remove it from mBodiesByName (j

Post by iforce2d » Mon Aug 26, 2013 7:42 pm

None of those variables or function names look familiar to me. What loader are you using?

If I had to guess, it looks like the 'scene' variable is a RUBE scene? And the getWorld obviously is the Box2D world. I don't know why you would expect destroying a body in the Box2D world to remove it from the scene as well. Box2D was around a long time before RUBE, and it doesn't know anything about editor formats.

notnowlewis
Posts: 8
Joined: Tue Jul 09, 2013 6:46 pm

Re: Removing a body does not remove it from mBodiesByName (j

Post by notnowlewis » Mon Aug 26, 2013 10:54 pm

Sorry, my mistake, it's the java rube loader linked to from your blog, my sleep deprived mind thought this would be the place to submit a bug for it... ignore me! :)

tescott
Posts: 68
Joined: Wed Feb 06, 2013 6:32 pm

Re: Removing a body does not remove it from mBodiesByName (j

Post by tescott » Tue Aug 27, 2013 1:03 am

If you are referring to this repo:

https://github.com/tescott/RubeLoader

...you can contact me about it.

The behavior describe is not a bug. Destroying a body in the Physics world has no bearing on the contents of the RUBE scene. The RUBE scene will help build the world for you and populate it, but once that is over its job is more or less done. So, there are no operations to go in and delete things out of the scene.

Furthermore, the putNamed method should actually only be used by one of the serializers... not by the application using the RubeLoader. In hindsight, we should have probably buried those methods down a level and provided a simpler interface for pulling scene data -- preventing a developer from trying access stuff he shouldn't be.


--tim

Post Reply