seg.fault when adding bodies to dyn. world

clemens
Posts: 3
Joined: Thu Jun 25, 2009 5:32 pm

seg.fault when adding bodies to dyn. world

Post by clemens »

hello,

i have built a test-scene with a btStaticPlaneShape and some boxes falling down from the sky.
all is fine - but if i increase the amount of boxes to over 1100 the application stops with a
seg.fault in function "dynamicsWorld->addRigidBody()".

here is the appropriate code:

Code: Select all

mCollShape = new btBoxShape( btVector3( width/2.0, height/2.0, depth/2.0 ) );
if( !mCollShape )
   return false;

btMatrix3x3 mat;
mat.setEulerZYX( degToRad(mNode->getRotation().Z), 
                        degToRad(mNode->getRotation().Y), 
                        degToRad(mNode->getRotation().X) );
      
btDefaultMotionState* boxMotionState =
                new btDefaultMotionState( btTransform( mat,btVector3( mNode->getPosition().X, 
                                                       mNode->getPosition().Y, mNode->getPosition().Z ) ) );
if( !boxMotionState )
   return false;

btVector3 inertia;
mCollShape->calculateLocalInertia( mass, inertia );

btConstructionInfo = new btRigidBody::btRigidBodyConstructionInfo( mass, boxMotionState, mCollShape, inertia);

if( !btConstructionInfo )
   return false;

btBody = new btRigidBody( *btConstructionInfo );
if( btBody )
   Physics::getPhysics()->dynamicsWorld->addRigidBody( btBody ); 
what maybe wrong here?
clemens
Posts: 3
Joined: Thu Jun 25, 2009 5:32 pm

Re: seg.fault when adding bodies to dyn. world

Post by clemens »

i have built bullet libs now in debug. the following function causes an assert due to the empty
handle (m_firstFreeHandle is 0) after i allocate over 1000 boxes:

Code: Select all

file: btAxisSweep3.h

template <typename BP_FP_INT_TYPE>
BP_FP_INT_TYPE btAxisSweep3Internal<BP_FP_INT_TYPE>::allocHandle()
{
	btAssert(m_firstFreeHandle);

	BP_FP_INT_TYPE handle = m_firstFreeHandle;
	m_firstFreeHandle = getHandle(handle)->GetNextFree();
	m_numHandles++;

	return handle;
}
clemens
Posts: 3
Joined: Thu Jun 25, 2009 5:32 pm

Re: seg.fault when adding bodies to dyn. world

Post by clemens »

hi,

this was my own mistake.
i just initialised the btAxisSweep3 with a constant of 1024 handles/proxies (taken
from an example code).
now it works with much more items, just by increasing the handles.
thanks,
clemens