Page 1 of 1

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

Posted: Mon Aug 26, 2013 7:02 pm
by notnowlewis
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.

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

Posted: Mon Aug 26, 2013 7:42 pm
by iforce2d
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.

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

Posted: Mon Aug 26, 2013 10:54 pm
by notnowlewis
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! :)

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

Posted: Tue Aug 27, 2013 1:03 am
by tescott
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