From 2e1b6ac8453cd1579908f8712ca9a0069787b82f Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 20 May 2009 15:07:41 +0100 Subject: Fix crash caused by non-removal of target. --- src/game-server/mapcomposite.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index df252761..448b3e45 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -512,6 +512,23 @@ bool MapComposite::insert(Thing *ptr) void MapComposite::remove(Thing *ptr) { + for (std::vector::iterator i = mContent->things.begin(), + i_end = mContent->things.end(); i != i_end; ++i) + { + if ((*i)->canFight()) + { + Being *being = static_cast(*i); + if (being->getTarget() == ptr) + { + being->setTarget(NULL); + } + } + if (*i == ptr) + { + i = mContent->things.erase(i); + } + } + if (ptr->isVisible()) { Actor *obj = static_cast< Actor * >(ptr); @@ -525,18 +542,6 @@ void MapComposite::remove(Thing *ptr) mContent->deallocate(static_cast< Being * >(ptr)); } } - - for (std::vector< Thing * >::iterator i = mContent->things.begin(), - i_end = mContent->things.end(); i != i_end; ++i) - { - if (*i == ptr) - { - *i = *(i_end - 1); - mContent->things.pop_back(); - return; - } - } - assert(false); } void MapComposite::setMap(Map *m) -- cgit v1.2.3-70-g09d2