diff options
author | Stijn Buys <ingar@osirion.org> | 2016-03-25 18:28:36 +0100 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2016-03-25 18:28:36 +0100 |
commit | 8b41b0b34c916486bb792c43fe9d4bdcc16c804b (patch) | |
tree | 7d0e5b25aadcaaa60677f461ed5a737bccec22d8 /src/game/base | |
parent | a54668eeaece112aad19e0bfd5197924602be001 (diff) |
Fixed a bad pointer bug when a ship explodes and ejects a weapon. Thanks to Thorn for finding it.
Diffstat (limited to 'src/game/base')
-rw-r--r-- | src/game/base/ship.cc | 5 |
1 files changed, 4 insertions, 1 deletions
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; } } |