[Orxonox-commit 4148] r8819 - code/branches/ai2/src/modules/pickup

dafrick at orxonox.net dafrick at orxonox.net
Wed Aug 3 21:54:19 CEST 2011


Author: dafrick
Date: 2011-08-03 21:54:19 +0200 (Wed, 03 Aug 2011)
New Revision: 8819

Modified:
   code/branches/ai2/src/modules/pickup/PickupSpawner.cc
Log:
Minor change in PickupSpawner, fixing possible cause for segfaults.


Modified: code/branches/ai2/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/ai2/src/modules/pickup/PickupSpawner.cc	2011-08-03 19:18:40 UTC (rev 8818)
+++ code/branches/ai2/src/modules/pickup/PickupSpawner.cc	2011-08-03 19:54:19 UTC (rev 8819)
@@ -180,7 +180,7 @@
         // If the PickupSpawner is active.
         if(GameMode::isMaster() && this->isActive())
         {
-            SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
+            WeakPtr<PickupSpawner> spawner = this; // Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
 
             // Remove PickupCarriers from the blocked list if they have exceeded their time.
             for(std::map<PickupCarrier*, std::time_t>::iterator it = this->blocked_.begin(); it != this->blocked_.end(); )
@@ -194,9 +194,12 @@
             // Iterate trough all Pawns.
             for(ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
             {
+                if(spawner == NULL) // Stop if the PickupSpawner has been deleted (e.g. because it has run out of pickups to distribute).
+                    break;
+
                 Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
                 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it);
-                // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawnder, is in trigger-distance and the carrier is not blocked.
+                // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawner, is in trigger-distance and the carrier is not blocked.
                 if(distance.length() < this->triggerDistance_ && carrier != NULL && this->blocked_.find(carrier) == this->blocked_.end())
                 {
                     if(carrier->isTarget(this->pickup_))




More information about the Orxonox-commit mailing list