Mass bug

I have been having loads of difficulties getting my mass stuff to work. I had alot of non-deterministic crashes. The crashed are memory violations. I think I have traced the fault to how the mass is associated with a Body.
I found that if I kept a reference to the original dMass object, not just the pointer, everything seemed to work. So I am thinking that SWIG is deallocating the memory when Java garbage collects the dMass object (becuase after Body construction there are no longer any pointers to the object). I beleive there are settings in SWIG to stop that happening, but I think it is much easier just to keep the reference.

Oh yeah. Further to that I found some strange things going on in the Body source. addGeom() calls setDefaultMass(), which may not be the behavior a user would expect. It basically means the last box or sphere that is added (NOT a transformed geometry) will erase all previous mass information and be used to define the mass.

I have also found it helpful for me to expose the mass Cptr so that I can use the low level mass routines.

OK, so what do you suggest then?

  • I’m happy to expose the mass pointer as an “unsupported” function. Do you mean the massId instance variable? I notice there is already a getMass.
  • where is the dereference/where should the reference be kept, I can’t see it
  • regarding setDefaultMass(), if we remove this, I guess people relying on this feature will need to change their code? Will it cause problems if it isn’t called? If so, we could make it backward compatable, but it may get even more confusing.

Regards,

Will.

Yeah. I was thinking about backward compatability. Perhaps setDefaultMass should stay in addGeom. An overloaded version could be addGeom(…, boolean setMass);
But even so, this method would still be a bit crappy because it would ignore GeomTransforms and a more expected behavior from a users point of view would be that the mass should be altered and not set. The ideal logic would use the low level mass functions for creating a mass for the underlying geom, translating that mass, and then adding the mass to the current mass parameters. Its one of those things that is probably 4 lines of code but quite hard to tell if its actually working or not so maybe this issue should be ignored.

As for the dMass reference in the constructor I see:


public Body(String name, World world, PlaceableGeom geom) {
....
dMass mass = new dMass();
massId = mass.getCPtr();

I am saying the mass object should be declared not as a local variable but as a field of Body, to avoid garbage collection.

Are you using the latest build from CVS? I committed fixes for both of these issues a while ago…

http://192.18.37.44/forums/index.php?topic=7822.0
http://192.18.37.44/forums/index.php?topic=7094.0