Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6533 for code/trunk


Ignore:
Timestamp:
Mar 16, 2010, 10:49:35 AM (15 years ago)
Author:
dafrick
Message:

Resolved segmentation fault, when destroying a PickupCompilation.

Location:
code/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/Pickup.cc

    r6524 r6533  
    7373    void Pickup::initializeIdentifier(void)
    7474    {       
    75         //TODO: Works?
    7675        std::string val1 = this->getActivationType();
    7776        std::string type1 = "activationType";
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r6524 r6533  
    6565    {
    6666        //! Destroy all Pickupables constructing this PickupCollection.
    67         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    68         {
    69             (*it)->destroy();
     67        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     68        {
     69            if((*it).get() != NULL)
     70                (*it).get()->destroy();
    7071        }
    7172    }
     
    8687    void PickupCollection::initializeIdentifier(void)
    8788    {
    88         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    89         {
    90             this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
     89        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     90        {
     91            this->pickupCollectionIdentifier_->addPickup((*it).get()->getPickupIdentifier());
    9192        }
    9293    }
     
    121122            return false;
    122123       
    123         this->pickups_.push_back(pickup);
     124        WeakPtr<Pickupable> ptr = pickup;
     125        this->pickups_.push_back(ptr);
    124126        return true;
    125127    }
     
    135137    const Pickupable* PickupCollection::getPickupable(unsigned int index)
    136138    {
    137         return this->pickups_[index]; //TODO. Does this work?
     139        return this->pickups_[index].get(); //TODO. Does this work?
    138140    }
    139141   
     
    143145       
    144146        //! Change used for all Pickupables this PickupCollection consists of.
    145         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    146         {
    147             (*it)->setUsed(this->isUsed());
     147        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     148        {
     149            (*it).get()->setUsed(this->isUsed());
    148150        }
    149151    }
     
    154156       
    155157        //! Change used for all Pickupables this PickupCollection consists of.
    156         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    157         {
    158             (*it)->setCarrier(this->getCarrier());
     158        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     159        {
     160            (*it).get()->setCarrier(this->getCarrier());
    159161        }
    160162    }
     
    165167       
    166168        //! Change the carrier for all Pickupables this PickupCollection consists of.
    167         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    168         {
    169             (*it)->setPickedUp(this->isPickedUp());
     169        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     170        {
     171            (*it).get()->setPickedUp(this->isPickedUp());
    170172        }
    171173    }
     
    179181       
    180182        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    181         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    182         {
    183             Pickupable* newPickup = (*it)->clone();
     183        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     184        {
     185            Pickupable* newPickup = (*it).get()->clone();
    184186            pickup->addPickupable(newPickup);
    185187        }
     
    190192    bool PickupCollection::isTarget(Identifier* identifier) const
    191193    {
    192         for(std::vector<Pickupable*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    193         {
    194             if(!(*it)->isTarget(identifier))
     194        for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     195        {
     196            if(!(*it).get()->isTarget(identifier))
    195197                return false;
    196198        }
  • code/trunk/src/modules/pickup/PickupCollection.h

    r6524 r6533  
    7979        private:
    8080           
    81             std::vector<Pickupable*> pickups_;
     81            std::vector<WeakPtr<Pickupable> > pickups_;
    8282       
    8383    };
  • code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc

    r6524 r6533  
    6464    PickupCarrier::~PickupCarrier()
    6565    {
    66         for(std::set<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     66        while(this->pickups_.size() > 0)
    6767        {
     68            std::set<Pickupable*>::iterator it = this->pickups_.begin();
     69            this->pickups_.erase(it);
    6870            (*it)->destroy();
    6971        }
    70        
     72
    7173        this->pickups_.clear();
    7274    }
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    r6524 r6533  
    4141#include "Pickupable.h"
    4242#include "core/Identifier.h"
     43#include "core/WeakPtr.h"
    4344
    4445#include "core/OrxonoxClass.h"
  • code/trunk/src/orxonox/interfaces/Pickupable.h

    r6524 r6533  
    114114                { return this->pickupIdentifier_; }
    115115               
    116             virtual void destroy(void)
    117                 { delete this; }
    118                
    119116            //TODO: Make them work as protected.
    120117            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
Note: See TracChangeset for help on using the changeset viewer.