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/worldentities/pawns
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.