[Orxonox-commit 5370] r10033 - in code/branches/modularships/src/orxonox: collisionshapes items worldentities worldentities/pawns

noep at orxonox.net noep at orxonox.net
Wed Apr 16 20:59:18 CEST 2014


Author: noep
Date: 2014-04-16 20:59:17 +0200 (Wed, 16 Apr 2014)
New Revision: 10033

Modified:
   code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc
   code/branches/modularships/src/orxonox/items/ShipPart.cc
   code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
   code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
   code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
   code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
Log:
Tried to find&solve the segfault. The detach-process itself is not the problem, but the collision on a deleted shape being handled. Maybe try using a smart pointer in the handling process, so that the shape only gets deleted when the process completed?

Modified: code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc
===================================================================
--- code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc	2014-04-16 18:59:17 UTC (rev 10033)
@@ -137,12 +137,15 @@
         // If the input CollisionShape is actually attached.
         if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
         {
+            orxout() << "Still going..." << endl;
             this->attachedShapes_.erase(shape);
             if (shape->getCollisionShape())
                 this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken?
             shape->notifyDetached();
+            orxout() << "Still going...." << endl;
 
             this->updatePublicShape();
+            orxout() << "Still going....." << endl;
         }
         else
             orxout(internal_warning) << "Cannot detach non child collision shape" << endl;

Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc	2014-04-16 18:59:17 UTC (rev 10033)
@@ -88,6 +88,7 @@
     void ShipPart::death()
     {
         this->parent_->removeShipPart(this);
+        orxout() << this->getName() << " has died." << endl;
     }
 
     /**

Modified: code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc	2014-04-16 18:59:17 UTC (rev 10033)
@@ -579,6 +579,7 @@
     void WorldEntity::detachCollisionShape(CollisionShape* shape)
     {
         // Note: The collision shapes may not be detached with this function!
+        orxout() << "WE: detachCS()" << endl;
         this->collisionShape_->detach(shape);
         // Note: this->collisionShape_ already notifies us of any changes.
     }

Modified: code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-04-16 18:59:17 UTC (rev 10033)
@@ -71,6 +71,7 @@
     class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState
     {
         friend class Scene;
+        friend class ModularSpaceShip;
 
         public:
             // Define our own transform space enum to avoid Ogre includes here

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	2014-04-16 18:59:17 UTC (rev 10033)
@@ -39,6 +39,7 @@
 
 #include "items/ShipPart.h"
 #include "worldentities/StaticEntity.h"
+#include "collisionshapes/WorldEntityCollisionShape.h"
 #include <BulletCollision/CollisionShapes/btCollisionShape.h>
 
 
@@ -77,7 +78,7 @@
     void ModularSpaceShip::updatePartAssignment()
     {
         // iterate through all attached objects
-        for (unsigned int i=0; i < this->getNumAttachedObj(); i++)
+        for (unsigned int i=0; i < (unsigned int)(this->getNumAttachedObj()); i++)
         {
             if (this->getAttachedObject(i) == NULL)
             {
@@ -178,6 +179,8 @@
 
         //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
 
+        orxout() << "CP before handleHit" << endl;
+
         if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
             this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
         else
@@ -275,14 +278,49 @@
         {
             if (itt->second == part)
             {
-                //this->detach(itt->first);
+                this->detach(itt->first);
                 //itt->first->destroy();
-                itt->first->setActive(false);
-                itt->first->setVisible(false);
-                itt->first->setCollisionResponse(false);
+                //itt->first->setActive(false);
+                //itt->first->setVisible(false);
+                //itt->first->setCollisionResponse(false);
+                //itt->first->setCollisionType(None);
+                //itt->first->deactivatePhysics();
                 this->partMap_.erase(itt);
             }
         }
     }
 
+    /**
+    @brief
+        Detaches a child WorldEntity from this instance.
+    */
+    void ModularSpaceShip::detach(WorldEntity* object)
+    {
+        std::set<WorldEntity*>::iterator it = this->children_.find(object);
+        if (it == this->children_.end())
+        {
+            orxout(internal_warning) << "Cannot detach an object that is not a child." << endl;
+            return;
+        }
+
+        // collision shapes
+        orxout() << "MSS: detach()" << endl;
+
+        this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
+        this->detachCollisionShape(object->collisionShape_);  // after succeeding, causes a crash in the collision handling
+        this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
+
+        // mass
+        if (object->getMass() > 0.0f)
+        {
+            this->childrenMass_ -= object->getMass();
+            recalculateMassProps();
+        }
+
+        this->detachNode(object->node_);
+        this->children_.erase(it);        // this causes a crash when unloading the level. Or not?
+
+        object->notifyDetached();
+        orxout() << "MSS: detach() completed." << endl;
+    }
 }

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	2014-04-11 10:07:05 UTC (rev 10032)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	2014-04-16 18:59:17 UTC (rev 10033)
@@ -117,6 +117,8 @@
             bool hasShipPart(ShipPart* part) const;
             void removeShipPart(ShipPart* part);
 
+            void detach(WorldEntity* object);
+
             virtual void updatePartAssignment();
 
         protected:




More information about the Orxonox-commit mailing list