that's always a bad idea.
you need to make a global vector and push any object that you want to destroy in a callback.
them after the newton update returns, you iterate over the vector and delete any object that was collected during the update.
care must be taken that you do not push teh same object more than once.
however if you want to do it like the way you are doing it now,
I fixed the function that does the deletion like this.
- Code: Select all
static void BreakHinge(const NewtonBody* body, dFloat timestep, int threadIndex)
{
NewtonWorld* const world = NewtonBodyGetWorld(body);
DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);
static unsigned atomicLock = 0;
if (scene->GetKeyState('1')) {
dCustomScopeLock lock(&atomicLock);
if (pHinge1) {
delete pHinge1;
pHinge1 = NULL;
}
}
if (scene->GetKeyState('2')) {
dCustomScopeLock lock(&atomicLock);
if (pHinge[0]) {
delete pHinge[0];
pHinge[0] = NULL;
delete pHinge[1];
pHinge[1] = NULL;
delete pHinge[2];
pHinge[2] = NULL;
}
}
}
basically you need to add an atomic spinlock so that onle one thread hit the same spot at a time.
That fixes the crash with multicore.
The problem with the zero dof, is related to the what I mentioned first. by deleting the the joint in the middle of an update, you are altering the joint topology.
the toplogy is only checked on the beginning of each update, if you delete a joint the unpredictable thing happens.
that said for this test case I made this change from this
- Code: Select all
DG_TRACKTIME(__FUNCTION__);
UpdateSkeletons();
UpdateBroadphase(timestep);
UpdateDynamics (timestep);
to this
- Code: Select all
DG_TRACKTIME(__FUNCTION__);
UpdateBroadphase(timestep);
UpdateSkeletons();
UpdateDynamics (timestep);
and is solve this particular case, but all it takes is some one deleting an object from a different callback and will break again, the proper fix in on the client side by garbage collect objects to be destroyed and actually delete them after the newton update returns.
sync to get the fix, but I will revert the change in the engine later, this is the kind of change that can cause bad side effects that can break other person code.