From: <yx...@us...> - 2012-02-24 13:25:45
|
Revision: 296 http://simspark.svn.sourceforge.net/simspark/?rev=296&view=rev Author: yxu Date: 2012-02-24 13:25:34 +0000 (Fri, 24 Feb 2012) Log Message: ----------- free ODE objects in correct order (assume there is only one world!) Modified Paths: -------------- trunk/spark/lib/oxygen/physicsserver/space.cpp trunk/spark/lib/oxygen/physicsserver/space.h trunk/spark/lib/oxygen/physicsserver/world.cpp trunk/spark/lib/oxygen/physicsserver/world.h trunk/spark/plugin/odeimps/odespace.cpp Modified: trunk/spark/lib/oxygen/physicsserver/space.cpp =================================================================== --- trunk/spark/lib/oxygen/physicsserver/space.cpp 2012-02-24 13:25:11 UTC (rev 295) +++ trunk/spark/lib/oxygen/physicsserver/space.cpp 2012-02-24 13:25:34 UTC (rev 296) @@ -193,50 +193,7 @@ mSpaceImp->PostPhysicsUpdateInternal(mContactGroupID); } -void Space::DestroySpaceObjects() -{ - boost::shared_ptr<Scene> scene = GetScene(); - if (scene.get() == 0) - { - return; - } - - TLeafList objects; - const bool recursive = true; - scene->ListChildrenSupportingClass<PhysicsObject>(objects, recursive); - - bool globalSpace = IsGlobalSpace(); - boost::shared_ptr<Space> self = shared_static_cast<Space>(GetSelf().lock()); - - for ( - TLeafList::iterator iter = objects.begin(); - iter != objects.end(); - ++iter - ) - { - boost::shared_ptr<PhysicsObject> object = shared_static_cast<PhysicsObject>(*iter); - if (object == self) - { - continue; - } - - // destroy objects registered to this space; the top level - // space object also destroy any other ODE object - const long parentSpace = object->GetParentSpaceID(); - if ( - ( - (globalSpace) && - (parentSpace == 0) - ) || - (parentSpace == mSpaceID) - ) - { - object->DestroyPhysicsObject(); - } - } -} - void Space::DestroyPhysicsObject() { if (mSpaceID == 0) @@ -244,10 +201,6 @@ return; } - // make sure that all objects registered to this space are destroyed - // before this space. Any other order provokes a segfault in ODE. - DestroySpaceObjects(); - mSpaceImp->DestroySpace(mContactGroupID, mSpaceID); mSpaceID = 0; Modified: trunk/spark/lib/oxygen/physicsserver/space.h =================================================================== --- trunk/spark/lib/oxygen/physicsserver/space.h 2012-02-24 13:25:11 UTC (rev 295) +++ trunk/spark/lib/oxygen/physicsserver/space.h 2012-02-24 13:25:34 UTC (rev 296) @@ -105,11 +105,6 @@ /** updates internal state after physics calculation */ virtual void PostPhysicsUpdateInternal(); - /** destroys the bodies managed by all Body objects that are - registered to this Space - */ - void DestroySpaceObjects(); - // // Members // Modified: trunk/spark/lib/oxygen/physicsserver/world.cpp =================================================================== --- trunk/spark/lib/oxygen/physicsserver/world.cpp 2012-02-24 13:25:11 UTC (rev 295) +++ trunk/spark/lib/oxygen/physicsserver/world.cpp 2012-02-24 13:25:34 UTC (rev 296) @@ -120,19 +120,48 @@ recurseLock = true; - boost::shared_ptr<World> space = GetWorld(); - if (space.get() != 0) - { - space->DestroyPhysicsObject(); - } - if (mWorldID == 0) { return; } + // first destory everthing in the world + DestroyWorldObjects(); + + // then destory the world + // otherwise, things in the world will destroied without notifying us mWorldImp->DestroyWorld(mWorldID); mWorldID = 0; recurseLock = false; } + + +void World::DestroyWorldObjects() +{ + boost::shared_ptr<Scene> scene = GetScene(); + + if (scene.get() == 0) + { + return; + } + + TLeafList objects; + const bool recursive = true; + scene->ListChildrenSupportingClass<PhysicsObject>(objects, recursive); + + boost::shared_ptr<World> self = shared_static_cast<World>(GetSelf().lock()); + + for (TLeafList::iterator iter = objects.begin(); iter != objects.end(); ++iter) + { + boost::shared_ptr<PhysicsObject> object = shared_static_cast<PhysicsObject>(*iter); + if (object == self) + { + continue; + } + + // destroy everthing in the world + // assume there is only ONE world + object->DestroyPhysicsObject(); + } +} Modified: trunk/spark/lib/oxygen/physicsserver/world.h =================================================================== --- trunk/spark/lib/oxygen/physicsserver/world.h 2012-02-24 13:25:11 UTC (rev 295) +++ trunk/spark/lib/oxygen/physicsserver/world.h 2012-02-24 13:25:34 UTC (rev 296) @@ -110,6 +110,11 @@ /** creates a new physics world */ virtual bool ConstructInternal(); + /** destroys the bodies managed by all objects that are + in Wthis World + */ + void DestroyWorldObjects(); + // // Members // Modified: trunk/spark/plugin/odeimps/odespace.cpp =================================================================== --- trunk/spark/plugin/odeimps/odespace.cpp 2012-02-24 13:25:11 UTC (rev 295) +++ trunk/spark/plugin/odeimps/odespace.cpp 2012-02-24 13:25:34 UTC (rev 296) @@ -87,6 +87,9 @@ dJointGroupDestroy(ODEContactGroup); } + // do not destroy geoms + dSpaceSetCleanup(SpaceImp, 0); + // release the ODE space dSpaceDestroy(SpaceImp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |