Manifolds overgrowing

blackbee
Posts: 2
Joined: Thu Sep 15, 2011 1:31 am

Manifolds overgrowing

Post by blackbee »

Hi there.
I'm having problem with overgrowing 'World.Dispatcher.NumManifold'. In my app there are walls of balls which are moving from one direction to another. I create a wall of.. let's say 100 balls (RigidBodies) apply them the same force, and when they reach certain point I remove them all. Repeat.
The problem is that along with new walls, Manifold number is growing (4096 is max) and it finaly crashes the app. I'm new to bullet so maby there is something I'm missing.

I tried to clean it somehow but after that I get access violations. I'm sure that I remove all bodies. 'NumOverlappingPairs' is the same as 'NumManifold'.
I uploaded a short movie showing that app and what I mean (that guy is just a mesh):

http://www.youtube.com/watch?v=ejeBUVoVCWs

As you can see Number of Manifolds is growing quite fast (that simulation will be much faster and with more balls)

Code in C#.

Code: Select all

// in constructor
broadphase = new DbvtBroadphase();
collisionConf = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConf);

World = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConf);
World.PerformDiscreteCollisionDetection();
World.Gravity = new Vector3(0, 0, 0);

collisionShapes = new AlignedCollisionShapeArray();
collisionShapes.Add(ballShape);

// creating new wall of balls and add force to it
for (j = 0; j < ballsNumber; j++)
{
	for (i = 0; i < ballsNumber; i++)
	{
		// set position for each ball
		currentBallPosition = spherePosition[j * ballsNumber + i];
		startTransform = Matrix.CreateTranslation(currentBallPosition) * Matrix.CreateRotationY(Dtr(90)) * rot;
		DefaultMotionState myMotionState = new DefaultMotionState(startTransform);

		// create rigidbody
		RigidBody body = LocalCreateRigidBody(1.0f, ballShape, myMotionState);  // simplified rigidbody maker with: World.AddRigidBody(body);
		body.CollisionFlags = CollisionFlags.NoContactResponse;                         // collisions are irrelevant
		World.AddCollisionObject(body);

		body.ApplyCentralImpulse(Vector3.UnitX); // force

		rigidMovingBodies.Add(body); // list of bodies
	}
}

// loops somwhere in Update method
for (int i = 0; i < rigidMovingBodies.Count; i++)
{
	if (balls reach certaint point)
	{
		World.RemoveCollisionObject((CollisionObject)rigidMovingBodies[i]);
		World.RemoveRigidBody(rigidMovingBodies[i]);
	}
}
// clean the list
for (int i = 0; i < rigidMovingBodies.Count; i++)
{
	if (balls reach certaint point)
	{
		rigidMovingBodies.RemoveAt(i);
		rigidBodiesStartPosition.RemoveAt(i);

	}
}
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Manifolds overgrowing

Post by Erwin Coumans »

This seems C# specific, it is best to contact the developers of the C# version.

Thanks,
Erwin
blackbee
Posts: 2
Joined: Thu Sep 15, 2011 1:31 am

Re: Manifolds overgrowing

Post by blackbee »

I solved it!
After commented out this line:

//World.AddCollisionObject(body);

Manifolds number go back to 0, when all objects are removed. Don't know if that's right thing to do, but problem is resolved. Seems that only RigidBody needs to be defined. So in my case:

World.AddRigidBody(body); // YES
World.AddCollisionObject(body); //NO

comments are welcome

@Erwin Coumans
For me it looks more like bullet thing, and my lack of knowledge. I doubt that C# wraper has anything to do with bullet itself. Hope they just imoprt functions from dll and parse them to C# without changing anything. That's what wrapers shoud do.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Manifolds overgrowing

Post by dphil »

Ah, yes I've had a similar issue before where I was mixing up addCollisionObject and addRigidBody. Makes sense though; if it's a rigid body, add it as a rigid body rather than the more generic collision object. You mention changing the code that adds a body; did you also remove the "removeCollisionObject" line? And just use the "removeRigidBody" line. Your original code was essentially trying to remove each ball from the world twice, one time treating it as a simple collision object, the other as a rigid body. I'm guessing the second, correct call (removeRigidBody) doesn't even do anything as the first call already removed the object (but as a simply collision object, meaning its rigid body aspects may not have been cleaned up properly, hence the overflow).
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Manifolds overgrowing

Post by xexuxjy »

Out of interest was it the wrapped version of Bullet or the pure c# version (BulletXNA) ? thanks