Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 16, 2014, 8:59:17 PM (11 years ago)
Author:
noep
Message:

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?

Location:
code/branches/modularships/src/orxonox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc

    r10003 r10033  
    138138        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    139139        {
     140            orxout() << "Still going..." << endl;
    140141            this->attachedShapes_.erase(shape);
    141142            if (shape->getCollisionShape())
    142143                this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken?
    143144            shape->notifyDetached();
     145            orxout() << "Still going...." << endl;
    144146
    145147            this->updatePublicShape();
     148            orxout() << "Still going....." << endl;
    146149        }
    147150        else
  • code/branches/modularships/src/orxonox/items/ShipPart.cc

    r10023 r10033  
    8989    {
    9090        this->parent_->removeShipPart(this);
     91        orxout() << this->getName() << " has died." << endl;
    9192    }
    9293
  • code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc

    r10003 r10033  
    580580    {
    581581        // Note: The collision shapes may not be detached with this function!
     582        orxout() << "WE: detachCS()" << endl;
    582583        this->collisionShape_->detach(shape);
    583584        // Note: this->collisionShape_ already notifies us of any changes.
  • code/branches/modularships/src/orxonox/worldentities/WorldEntity.h

    r10029 r10033  
    7272    {
    7373        friend class Scene;
     74        friend class ModularSpaceShip;
    7475
    7576        public:
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10029 r10033  
    4040#include "items/ShipPart.h"
    4141#include "worldentities/StaticEntity.h"
     42#include "collisionshapes/WorldEntityCollisionShape.h"
    4243#include <BulletCollision/CollisionShapes/btCollisionShape.h>
    4344
     
    7879    {
    7980        // iterate through all attached objects
    80         for (unsigned int i=0; i < this->getNumAttachedObj(); i++)
     81        for (unsigned int i=0; i < (unsigned int)(this->getNumAttachedObj()); i++)
    8182        {
    8283            if (this->getAttachedObject(i) == NULL)
     
    179180        //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
    180181
     182        orxout() << "CP before handleHit" << endl;
     183
    181184        if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
    182185            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
     
    276279            if (itt->second == part)
    277280            {
    278                 //this->detach(itt->first);
     281                this->detach(itt->first);
    279282                //itt->first->destroy();
    280                 itt->first->setActive(false);
    281                 itt->first->setVisible(false);
    282                 itt->first->setCollisionResponse(false);
     283                //itt->first->setActive(false);
     284                //itt->first->setVisible(false);
     285                //itt->first->setCollisionResponse(false);
     286                //itt->first->setCollisionType(None);
     287                //itt->first->deactivatePhysics();
    283288                this->partMap_.erase(itt);
    284289            }
     
    286291    }
    287292
     293    /**
     294    @brief
     295        Detaches a child WorldEntity from this instance.
     296    */
     297    void ModularSpaceShip::detach(WorldEntity* object)
     298    {
     299        std::set<WorldEntity*>::iterator it = this->children_.find(object);
     300        if (it == this->children_.end())
     301        {
     302            orxout(internal_warning) << "Cannot detach an object that is not a child." << endl;
     303            return;
     304        }
     305
     306        // collision shapes
     307        orxout() << "MSS: detach()" << endl;
     308
     309        this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
     310        this->detachCollisionShape(object->collisionShape_);  // after succeeding, causes a crash in the collision handling
     311        this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
     312
     313        // mass
     314        if (object->getMass() > 0.0f)
     315        {
     316            this->childrenMass_ -= object->getMass();
     317            recalculateMassProps();
     318        }
     319
     320        this->detachNode(object->node_);
     321        this->children_.erase(it);        // this causes a crash when unloading the level. Or not?
     322
     323        object->notifyDetached();
     324        orxout() << "MSS: detach() completed." << endl;
     325    }
    288326}
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10023 r10033  
    118118            void removeShipPart(ShipPart* part);
    119119
     120            void detach(WorldEntity* object);
     121
    120122            virtual void updatePartAssignment();
    121123
Note: See TracChangeset for help on using the changeset viewer.