all show must end, so do i need to delete the shapes?

khoowaikeong
Posts: 43
Joined: Fri Jun 15, 2012 7:11 am

all show must end, so do i need to delete the shapes?

Post by khoowaikeong »

my clean up code:

Code: Select all

			if(pRigidBody)
			{
				if(pColliderScene) 
				{
					pColliderScene->getDynamicsWorld()->removeRigidBody(pRigidBody);
					pColliderScene = NULL;
				}				
				delete pRigidBody;
				pRigidBody = NULL;
			}
			// delete pCollisionShape; <--- do i need to delete shape?
do i need to remove the shape i use in pRigidBody->setShape(pCollisionShape); ?

and if those shape are compound of other shape do they get deleted by the compound shape or do i need to store pointer to everything and delete them meeself?
:oops:
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: all show must end, so do i need to delete the shapes?

Post by Flix »

Indeed you should delete all the btCollisionShapes you use.
Of course you might reuse the same shape multiple times (e.g. when you scale them through a btUniformScalingShape, or simply when multiple bodies share the same shape) and you must be careful not to delete shared shapes too early.

I use a class that I've made that collects the shapes for me. I've posted about it long time ago (http://bulletphysics.org/Bullet/phpBB3/ ... eCollector), (although the most up to date version can probably be found in the source code of this project: http://bulletphysics.org/Bullet/phpBB3/ ... hilit=HACD).

P.S. It's not "the state of the art", but I find it very useful for my programs.