hkpSampledHeightFieldShape Crash on release

hkpSampledHeightFieldShape Crash on release

OK,I have an infinite world with many HavokWorld instances, each being a 1km cube. Works great.Terrain is done in 64x64 meter chunks, so a terrain grid is 4096 altitude points.A have a class,MySampledHeightFieldShape, that implements virtual void collideSpheres( const CollideSpheresInput& input, SphereCollisionOutput* outputArray) constetc.My TerrainNode class is the 64x64 chunk. If I create TerrainNodes and never delete them, I don't crash.As the player moves throught the world I create TerrainNodes ahead of them, and remove them behind them (if further than 1Km away).But in the destructor for TerrainNode if I free up the HavokhkpRigidBody for the terrain, I later crash because aMySampledHeightFieldShape::collideSpheres gets called on ahkpRigidBody that has been deleted.The creation is like this...
hkpSampledHeightFieldBaseCinfo ci; ci.m_xRes = 65; ci.m_zRes = 65; MySampledHeightFieldShape * heightFieldShape = new MySampledHeightFieldShape(ci , n); // Now that we have a shape all we need is the fixed body to represent it in the // the simulation. Standard rigid body setup. { hkpRigidBodyCinfo rci; rci.m_motionType = hkpMotion::MOTION_FIXED; rci.m_position.setMul4( -0.5f, heightFieldShape->m_extents ); // center the heightfield rci.m_shape = heightFieldShape; rci.m_friction = 0.2f; hkpRigidBody * body = new hkpRigidBody( rci ); hkVector4 pos; float offset = (n->m_sizeInTiles - 1.0f) * 0.5f * n->m_scale; LocalPosition lp = n->getWorldPosition().scenarioBlockRelativePosition(); pos(0) = lp.x - TDLHALFBLOCKSIZE - offset; pos(1) = 0.0f; pos(2) = lp.z - TDLHALFBLOCKSIZE - offset; body->setPosition(pos); n->m_havokBodyTerrain = body; n->m_havokBodyTerrain->addReference(); n->m_havokBodyTerrain->setCollisionFilterInfo(hkpGroupFilter::calcFilterInfo(HK_TDL_LAYER_TERRAIN)); // Default from Havok is 0.2 n->m_havokBodyTerrain->setFriction(0.9f); // 0.99 is rubber ball n->m_havokBodyTerrain->setRestitution(0.3f); m_parent->m_havokWorld->addEntity(body); body->removeReference(); } // Just need to remove the reference we hold to the shape, and that is it. heightFieldShape->removeReference();Then when the TerrainNode is deleted...
if(m_havokBodyTerrain != NULL) { ASSERT_VALID_PTR(m_havokBodyTerrain); m_owner->m_havokWorld->removeEntity(m_havokBodyTerrain); m_havokBodyTerrain->removeReference(); m_havokBodyTerrain = NULL; }I do not explicitly delete theMySampledHeightFieldShape, and I remove the references to them_havokBodyTerrain which should cause it to get deleted.Any idea on this?

2 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de havok_David

Hello Richard,

The add/remove Reference function calls in the code shown above looks good. In order to help you, I am trying to do a repro of your crash by creating a scene with several height field shapes which I can delete at run-time however I do not get the crash that you are describing.
The code that you are describing looks very similar to one of our demos, namely the "Physics\Api\Collide\Shapes\HeightField\SampledHeightField\SampledHeightFieldDemo.h/.cpp". If you use the deletion code you gave in your post in the the actual demo, does it still crash? If not, could you try merging your code onto the demo code part by part until it crashes? When it crashes, could you then tell me exactly what are the changes you made from the initial demo as well as give me the call-stack when your application crashes? This would help me get a better understanding of the crash you are encountering.

Another thing you could try is removing all the objects in your scene except two of your TerrainNodes. If it doesn't crash when you remove them, add all your other scene objects progressively until it crashes. Can you figure out what kind of object makes your application crash? A specific object might be the cause of your crash if the crashing collideSpheres function is called from the hkpHeightFieldAgent which is responsible of processing collisions between the MySampledHeightFieldShape and another object of your scene.

Cheers,
David Grosman.

David G. Developer Support Engineer Havok www.havok.com

Faça login para deixar um comentário.