Sign in to follow this  
Tct

PhysX: createActor/releaseActor memory problems

Recommended Posts

Hi, I have serious memory problems with PhysX and was wandering if someone could help me out. So here's what I am doing: 1. Create NxPhysXSDK 2. Create NxPhysXScene 3. Perform a loop with creating/releasing static object
int iterate = 10000;
for(int i=0;i<iterate ;i++)
{
	NxBoxShapeDesc boxDesc;
	boxDesc.dimensions = NxVec3((float)size, (float)size, (float)size);

	NxActorDesc actorDesc;
	actorDesc.shapes.pushBack(&boxDesc);
	actorDesc.globalPose.t  = pos;
	NxActor* actor = gScene->createActor(actorDesc);
	gScene->releaseActor(*actor);
}
As you can see, after creating an actor, I am releasing it, so logically thinking, I should have the same memory amount as before creating/releasing those actors, of course due to fragmentation, it may slightly increase.... But memory amount consumed is in megabytes, which firstly looked like a leak. After some investigation, I noticed that the similar code:
int iterate = 10000;
for(int i=0;i<iterate ;i++)
{
	NxBoxShapeDesc boxDesc;
	boxDesc.dimensions = NxVec3((float)size, (float)size, (float)size);

	NxActorDesc actorDesc;
	actorDesc.shapes.pushBack(&boxDesc);
	actorDesc.globalPose.t  = pos;
	NxActor* actor = gScene->createActor(actorDesc);
	gScene->releaseActor(*actor);
        gScene->simulate(0.01f);
}
won't produce this so called 'leak', so this makes me think, that PhysX has some kind of pool inside, which is reseted after simulate is called. The thing is that I can't call simulate, because I am in so called edit mode, that means no physics should be performed. Another thing which you might ask why I am creating/releasing actors, it's because it's a static object, and it cannot be moved (according to PhysX documentation), so the only way to 'move it' is to recreate it. So in short, does anyone know how to reset that inner PhysXScene pool, so memory wouldn't be consumed so much? P.S gScene->simulate(0.0f), won't work Thx

Share this post


Link to post
Share on other sites
I believe the reason behind the behavior is more because of PhysX deferred the deletion of actors events probably for simulation stability purposes but this is just my guess.

If you need to move the objects, I suggest making the object kinematics rather than static. Static are meant for object that doesn't move. You might want to represents them differently in your editor (kinematic) and your game (static).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this