[SOLVED] Callbacks not being called after body recreated

Gila

08-05-2006 09:10:16

I have just encountered a very strange problem which seems like either a bug in Newton/OgreNewt or just a strange behaviour caused by what I'm doing.... hope you can help...

In my game I have objects that can change shape as the game progresses - chunks of objects may be detached and glued onto other objects.

I've implemented this by having each of my GameObjects contain a pointer to an OgreNewt::Body which is created in the initial shape at creation time. Part of this creation stage also assigns the custom force callback, which is a member of my GameObject and uses the state of the GameObject to generate the appropriate extra forces (e.g. dragging by the player).

When a shape gets modified I have a function something like this:


- Delete the current Body (storing the position, velocity, etc)
- Generate a new Collision for the new shape of the object
- Generate a new Body using this Collision
- Set the force callback, i.e.
pBody->setCustomForceAndTorqueCallback( fastdelegate::MakeDelegate( this, &GameObject::customForceCallback) );
- Restore position, velocity, etc. from the old body.


What happens is that customForceCallback is no longer called (a breakpoint in the function is never hit).

Unfortunately it would be hard to reduce my actual code to a minimal example to repro this. If necessary though, I could probably hack one of the OgreNewt demos to try and create the same situation.

Thanks in advance for any help.. it's making me pretty sad!

Gila

08-05-2006 09:17:16

Hmm... after a bit more investigation it seems like the callback only stops being called when there are no forces being applied. For example:

- I start dragging an object (forces correctly applied at this point)
- I press a debug key to recreate the Body
- (forces still being applied ok)
- I stop dragging)
- (Forces no longer applied, and callback no longer being called.)

If I'm not dragging when the body is recreated the callback dies right then.

[By the way, I am definitely calling unFreeze() and setAutoFreeze(false) on the new Body...]


:?: :cry:

Gila

08-05-2006 09:32:26

:roll:

Ok, I had one code path where unfreeze() WAS called and one where it wasn't.

Guess which path the debug "recreate bodies" code was in....

So, the moral of story: Check the temperature of your body.

I'll leave this up incase any of this is useful to anyone :)