From 8b41b0b34c916486bb792c43fe9d4bdcc16c804b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 25 Mar 2016 18:28:36 +0100 Subject: Fixed a bad pointer bug when a ship explodes and ejects a weapon. Thanks to Thorn for finding it. --- src/game/base/ship.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/game') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index cc583d9..b1e0574 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -450,6 +450,7 @@ void Ship::explode() if ((*it)->info()->type() == Cargo::infotype()) { long loss = (*it)->amount() * ((long) percentage) / 100l; if (loss > 0) { + // eject potentially deletes the item the iterator is pointing to eject((*it++), loss, false); continue; } @@ -463,7 +464,9 @@ void Ship::explode() while (it != inventory()->items().end()) { if ((*it)->info()->type() == Weapon::infotype()) { if (math::randomf(100.0f) < 10.0f) { - eject((*it++), (*it)->amount(), false); + // eject potentially deletes the item the iterator is pointing to + float amount = (*it)->amount(); + eject((*it++), amount, false); continue; } } -- cgit v1.2.3