[Orxonox-commit 1815] r6533 - in code/trunk/src: modules/pickup orxonox/interfaces
dafrick at orxonox.net
dafrick at orxonox.net
Tue Mar 16 10:49:35 CET 2010
Author: dafrick
Date: 2010-03-16 10:49:35 +0100 (Tue, 16 Mar 2010)
New Revision: 6533
Modified:
code/trunk/src/modules/pickup/Pickup.cc
code/trunk/src/modules/pickup/PickupCollection.cc
code/trunk/src/modules/pickup/PickupCollection.h
code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
code/trunk/src/orxonox/interfaces/PickupCarrier.h
code/trunk/src/orxonox/interfaces/Pickupable.h
Log:
Resolved segmentation fault, when destroying a PickupCompilation.
Modified: code/trunk/src/modules/pickup/Pickup.cc
===================================================================
--- code/trunk/src/modules/pickup/Pickup.cc 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/modules/pickup/Pickup.cc 2010-03-16 09:49:35 UTC (rev 6533)
@@ -72,7 +72,6 @@
*/
void Pickup::initializeIdentifier(void)
{
- //TODO: Works?
std::string val1 = this->getActivationType();
std::string type1 = "activationType";
this->pickupIdentifier_->addParameter(type1, val1);
Modified: code/trunk/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupCollection.cc 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/modules/pickup/PickupCollection.cc 2010-03-16 09:49:35 UTC (rev 6533)
@@ -64,9 +64,10 @@
PickupCollection::~PickupCollection()
{
//! Destroy all Pickupables constructing this PickupCollection.
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it)->destroy();
+ if((*it).get() != NULL)
+ (*it).get()->destroy();
}
}
@@ -85,9 +86,9 @@
void PickupCollection::initializeIdentifier(void)
{
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
+ this->pickupCollectionIdentifier_->addPickup((*it).get()->getPickupIdentifier());
}
}
@@ -120,7 +121,8 @@
if(pickup == NULL)
return false;
- this->pickups_.push_back(pickup);
+ WeakPtr<Pickupable> ptr = pickup;
+ this->pickups_.push_back(ptr);
return true;
}
@@ -134,7 +136,7 @@
*/
const Pickupable* PickupCollection::getPickupable(unsigned int index)
{
- return this->pickups_[index]; //TODO. Does this work?
+ return this->pickups_[index].get(); //TODO. Does this work?
}
void PickupCollection::changedUsed(void)
@@ -142,9 +144,9 @@
SUPER(PickupCollection, changedUsed);
//! Change used for all Pickupables this PickupCollection consists of.
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it)->setUsed(this->isUsed());
+ (*it).get()->setUsed(this->isUsed());
}
}
@@ -153,9 +155,9 @@
SUPER(PickupCollection, changedCarrier);
//! Change used for all Pickupables this PickupCollection consists of.
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it)->setCarrier(this->getCarrier());
+ (*it).get()->setCarrier(this->getCarrier());
}
}
@@ -164,9 +166,9 @@
SUPER(PickupCollection, changedPickedUp);
//! Change the carrier for all Pickupables this PickupCollection consists of.
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it)->setPickedUp(this->isPickedUp());
+ (*it).get()->setPickedUp(this->isPickedUp());
}
}
@@ -178,9 +180,9 @@
SUPER(PickupCollection, clone, item);
PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
- for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- Pickupable* newPickup = (*it)->clone();
+ Pickupable* newPickup = (*it).get()->clone();
pickup->addPickupable(newPickup);
}
@@ -189,9 +191,9 @@
bool PickupCollection::isTarget(Identifier* identifier) const
{
- for(std::vector<Pickupable*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- if(!(*it)->isTarget(identifier))
+ if(!(*it).get()->isTarget(identifier))
return false;
}
Modified: code/trunk/src/modules/pickup/PickupCollection.h
===================================================================
--- code/trunk/src/modules/pickup/PickupCollection.h 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/modules/pickup/PickupCollection.h 2010-03-16 09:49:35 UTC (rev 6533)
@@ -78,7 +78,7 @@
private:
- std::vector<Pickupable*> pickups_;
+ std::vector<WeakPtr<Pickupable> > pickups_;
};
Modified: code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc 2010-03-16 09:49:35 UTC (rev 6533)
@@ -63,11 +63,13 @@
PickupCarrier::~PickupCarrier()
{
- for(std::set<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ while(this->pickups_.size() > 0)
{
+ std::set<Pickupable*>::iterator it = this->pickups_.begin();
+ this->pickups_.erase(it);
(*it)->destroy();
}
-
+
this->pickups_.clear();
}
Modified: code/trunk/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/trunk/src/orxonox/interfaces/PickupCarrier.h 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/orxonox/interfaces/PickupCarrier.h 2010-03-16 09:49:35 UTC (rev 6533)
@@ -40,6 +40,7 @@
#include <set>
#include "Pickupable.h"
#include "core/Identifier.h"
+#include "core/WeakPtr.h"
#include "core/OrxonoxClass.h"
Modified: code/trunk/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/trunk/src/orxonox/interfaces/Pickupable.h 2010-03-15 16:20:26 UTC (rev 6532)
+++ code/trunk/src/orxonox/interfaces/Pickupable.h 2010-03-16 09:49:35 UTC (rev 6533)
@@ -113,9 +113,6 @@
virtual const PickupIdentifier* getPickupIdentifier(void)
{ return this->pickupIdentifier_; }
- virtual void destroy(void)
- { delete this; }
-
//TODO: Make them work as protected.
bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
More information about the Orxonox-commit
mailing list