Bullet 2.58 GIMPACT pool allocator issue

User avatar
projectileman
Posts: 109
Joined: Thu Dec 14, 2006 4:27 pm
Location: Colombia

Bullet 2.58 GIMPACT pool allocator issue

Post by projectileman »

Hi.
I've been tracing the GIMPACT concave demo with Bullet v2.5.8, and I've noted that the problem with the Pool Allocator comes when releaseManifold is called.

The btGImpactCollisionAlgorithm class calls releaseManifold very often. All problems begin when this function is called:

Code: Select all

SIMD_FORCE_INLINE void clearCache()
	{
		if(m_manifoldPtr)
		{
			//m_manifoldPtr->clearManifold();
			m_dispatcher->releaseManifold(m_manifoldPtr);
			m_manifoldPtr = NULL;
		}
		destroyConvexAlgorithm();

		m_triface0 = -1;
		m_part0 = -1;
		m_triface1 = -1;
		m_part1 = -1;
	}
ClearCache releases the previous contact Manifold point in the algorithm for a new collision query.

And these are the cases when clearCache() is called:
  • When creating a new Manifold point:

    Code: Select all

           SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(
                                 btCollisionObject* body0,btCollisionObject* body1)
    	{
    		clearCache();
    		m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
    		return m_manifoldPtr;
    	}
    
  • When processing the collision:

    Code: Select all

    void btGImpactCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
    {
        clearCache();
    
        m_resultOut = resultOut;
    	m_dispatchInfo = &dispatchInfo;
    ...
    ...
    ...
    
  • When destroying the algorithm:

    Code: Select all

    btGImpactCollisionAlgorithm::~btGImpactCollisionAlgorithm()
    {
    	clearCache();
    }
    
Well, it seems evident that btGImpactCollisionAlgorithm calls releaseManifold more times than the other algorithms.

That's the way I've implemented it because I thought it as the correctly way at that moment. But now happens that the new btPoolAllocator class gives problems when releasing memory sometimes.

So the question is, in which case I need to call m_dispatcher->releaseManifold(m_manifoldPtr) ?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bullet 2.58 GIMPACT pool allocator issue

Post by Erwin Coumans »

This seems to happen only with older GIMPACT versions. The GIMPACT that ships with Bullet has been fixed to work:

Code: Select all

struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
	{
		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
		{
			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm));
			return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1);
		}
	};
Basically, the btGImpactCollisionAlgorithm needs to be allocated using the dispatcher/pool allocator.
Does that work?
Thanks!
Erwin