Reset of world

O-san
Posts: 19
Joined: Mon May 11, 2009 8:46 am

Reset of world

Post by O-san »

Hello!

I am having problem tracking down a slowdown caused by stepSimulation(). The problem arise when I start my simulation for the second time. This is what happens; when I'm at the end of the first simulation and I want to begin from scratch I first remove all rigid bodies, motion states and shapes from the world. I then reload everything (graphics and what not) and recreate all the bodies, shapes, motion states again. Now the slowdown occurs.

I have clocked my function calls and found out that stepSimulation slows down from a healthy 0.2-1ms to 62ms the second time around.

I've tired to fix this by deleting and recreating the physics objects (dynamics world, solver, collision configuration, dispatcher and broad phase). This seems to solve the problem but I can't understand why and hence I am worried that the problem might occur in some situations again.

Is there something more I should be doing besides deleting the rigid bodies, motion states and shapes when setting up a new world? For the broad phase algorithm I use btDbvtBroadphase. I also use collision masks.

Thanks for any insight.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Reset of world

Post by Mako_energy02 »

I'm not sure if this will fix it for you, but I've made a function to attempt to clear all physics meta data from the simulation to get it back to as close to pristine working condition as possible. I have no slowdown between simulations but you may also be doing something else. In either case here's some code you can try for yourself:

Code: Select all

    void PhysicsManager::ClearPhysicsMetaData()
    {
        // Clean the broadphase of AABB data
        btOverlappingPairCache* Pairs = BulletBroadphase->getOverlappingPairCache();
        int NumPairs = Pairs->getNumOverlappingPairs();
        btBroadphasePairArray PairArray = Pairs->getOverlappingPairArray();
        for( Whole X = 0 ; X < NumPairs ; X++ )
        {
            btBroadphasePair& CurrPair = PairArray.at(X);
            Pairs->cleanOverlappingPair(CurrPair,BulletDispatcher);
            Pairs->removeOverlappingPair(CurrPair.m_pProxy0,CurrPair.m_pProxy1,BulletDispatcher);
        }

        // Clean the dispatcher(narrowphase) of shape data
        int numManifolds = BulletDynamicsWorld->getDispatcher()->getNumManifolds();
        for ( int i = 0 ; i < numManifolds ; i++ )
        {
            BulletDispatcher->releaseManifold(BulletDispatcher->getManifoldByIndexInternal(i));
        }

        BulletBroadphase->resetPool(BulletDispatcher);
        BulletSolver->reset();
        BulletDynamicsWorld->stepSimulation(1.f/60.f,1,1.f/60.f);
    }
Most of that should be fairly self explanitory. At the end I step the simulation to ensure any additional hidden/internal structures that are difficult to access get updated and are made aware the simulation is empty. Note that all this logic is called AFTER all collision objects, actions, etc. have been removed from the world.