Memory leak with 0.9-38 and TerrainShape?

DaveC

17-03-2008 16:45:57

Note: This is probably my own fault somewhere

I have the NxOgre::World object created just once for the entire application...

NxOgre::PhysXDriverParams params;
params.setToDefault();
params.useFrameListener = false;
params.logtype = NxOgre::PhysXDriverParams::LT_TEXT;
mpWorld = new NxOgre::World(params);


Then, to reset/create the scene, I have myself a reset method
which creates the scene with default values (and also destroys it if it's been created on a previous call to this reset method)...

void SCPhysics::reset(SceneManager *pSceneManager, String strTerrainHeightmapName)
{
if (mpScene)
{
mpWorld->destroyScene("PhysicsScene");
mpScene = 0;
}

// Create physics scene
NxOgre::SceneParams sceneParams;
sceneParams.setToDefault();
sceneParams.floor = true;
sceneParams.gravity = NxVec3(0.0f, -9.81f, 0.0f);
sceneParams.max_iter = 8;
sceneParams.max_timestep = 1.0f/60.0f;
mpScene = mpWorld->createScene("PhysicsScene", pSceneManager, sceneParams);


Now, if I call the reset method every frame (for testing purposes to "simulate" a reset), no memory leaks are found as expected, but as soon as I add the following code to create the scene's terrain actor, each time the scene is reset, I'm loosing memory :/

// New version of above method with additional create terrain actor code added...

void SCPhysics::reset(SceneManager *pSceneManager, String strTerrainHeightmapName)
{
if (mpScene)
{
mpWorld->destroyScene("PhysicsScene");
mpScene = 0;
}

// Create physics scene
NxOgre::SceneParams sceneParams;
sceneParams.setToDefault();
sceneParams.floor = true;
sceneParams.gravity = NxVec3(0.0f, -9.81f, 0.0f);
sceneParams.max_iter = 8;
sceneParams.max_timestep = 1.0f/60.0f;
mpScene = mpWorld->createScene("PhysicsScene", pSceneManager, sceneParams);



// Create terrain actor from height map
if (strTerrainHeightmapName.size() > 0)
{
Vector3 vTerrainScale(5000.0f / 512.0f, 1.0f, 5000.0f / 512.0f);
NxOgre::ShapeParams shapeParams;
shapeParams.setToDefault();
shapeParams.mMeshScale = NxVec3(vTerrainScale.x, vTerrainScale.y, vTerrainScale.z);
NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 0.0f;
actorParams.mDensity = 0.0f;
actorParams.mLinearDamping = 0.75f;
actorParams.mAngularDamping = 0.75f;
actorParams.mNodeScale = vTerrainScale;
NxOgre::Pose pose(Vector3::ZERO, Quaternion::IDENTITY);
NxOgre::TerrainShape *ts = new NxOgre::TerrainShape(strTerrainHeightmapName, 500.0f, shapeParams);
NxOgre::Actor* pActorTerrain = mpScene->createActor("terrain", ts , pose, actorParams);
}
}

Now, I'm pretty sure it's my own fault, I'm just wondering where I'm going wrong :(
At first, I thought that the line that goes...
NxOgre::TerrainShape *ts = new NxOgre::TerrainShape(strTerrainHeightmapName, 500.0f, shapeParams);
was the culprit, but I tried deleting the *ts pointer, but it seems NxOgre handles cleaning that up for us.

The memory increases approx 1Meg per reset (the heightmap image is 513x513 in resolution).

I'm sorry to be a pain, but if somebody could point out where I'm going wrong, I'd be your best friend, forever! :)

betajaen

17-03-2008 16:55:11

I remember Luis pointing out to me one time, that the TerrainShape was causing a leak. However at the end of shutdown the PhysX SDK should clean it up for us anyway.

If you can get a copy of the NxHeightmapMesh. You can tell the PhysXSDK (mWorld->getPhysXDriver()->getSDK()) to release it, once you've done with that terrain.

I wouldn't worry about posting a fix though; Bleeding is coming soon with a new resource system that tracks these things.

DaveC

17-03-2008 17:18:47

Thanks for the reply
betajaen.incFriendsForever(1); // ;)

I look forward to the next release, thanks for working on NxOgre!