[Orxonox-commit 7090] r11707 - code/trunk/src/modules/pickup
landauf at orxonox.net
landauf at orxonox.net
Sat Jan 6 16:34:19 CET 2018
Author: landauf
Date: 2018-01-06 16:34:18 +0100 (Sat, 06 Jan 2018)
New Revision: 11707
Modified:
code/trunk/src/modules/pickup/PickupSpawner.cc
Log:
fixed nullptr access when two pawns trigger a pickup-spawner at the same time (for the second pawn in the list, the pickup is already nullptr -> crash)
Modified: code/trunk/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupSpawner.cc 2018-01-06 14:27:49 UTC (rev 11706)
+++ code/trunk/src/modules/pickup/PickupSpawner.cc 2018-01-06 15:34:18 UTC (rev 11707)
@@ -157,9 +157,6 @@
// Iterate trough all Pawns.
for(Pawn* pawn : ObjectList<Pawn>())
{
- if(spawner == nullptr) // Stop if the PickupSpawner has been deleted (e.g. because it has run out of pickups to distribute).
- break;
-
Vector3 distance = pawn->getWorldPosition() - this->getWorldPosition();
PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn);
// 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.
@@ -166,7 +163,10 @@
if(distance.length() < this->triggerDistance_ && carrier != nullptr && this->blocked_.find(carrier) == this->blocked_.end())
{
if(carrier->isTarget(this->pickup_))
- this->trigger(pawn);
+ {
+ this->trigger(pawn); // Attention: after this line, pickup_ is probably nullptr (because it was taken) and even spawner can be nullptr (if it run out of pickups)!
+ break;
+ }
}
}
}
More information about the Orxonox-commit
mailing list