Skip to content

Commit

Permalink
fix: crash when monster pulls items from a tile (opentibiabr#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah authored Jul 26, 2024
1 parent 1a6dac4 commit fa85e18
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,27 +1129,23 @@ void Monster::pushItems(std::shared_ptr<Tile> tile, const Direction &nextDirecti
// We can not use iterators here since we can push the item to another tile
// which will invalidate the iterator.
// start from the end to minimize the amount of traffic
TileItemVector* items;
if (!(items = tile->getItemList())) {
return;
}
uint32_t moveCount = 0;
uint32_t removeCount = 0;
auto it = items->begin();
while (it != items->end()) {
std::shared_ptr<Item> item = *it;
if (item && item->hasProperty(CONST_PROP_MOVABLE) && (item->hasProperty(CONST_PROP_BLOCKPATH) || item->hasProperty(CONST_PROP_BLOCKSOLID)) && item->canBeMoved()) {
if (moveCount < 20 && pushItem(item, nextDirection)) {
++moveCount;
} else if (!item->isCorpse() && g_game().internalRemoveItem(item) == RETURNVALUE_NOERROR) {
++removeCount;
if (const auto items = tile->getItemList()) {
uint32_t moveCount = 0;
uint32_t removeCount = 0;
int32_t downItemSize = tile->getDownItemCount();
for (int32_t i = downItemSize; --i >= 0;) {
const auto &item = items->at(i);
if (item && item->hasProperty(CONST_PROP_MOVABLE) && (item->hasProperty(CONST_PROP_BLOCKPATH) || item->hasProperty(CONST_PROP_BLOCKSOLID)) && item->canBeMoved()) {
if (moveCount < 20 && pushItem(item, nextDirection)) {
++moveCount;
} else if (!item->isCorpse() && g_game().internalRemoveItem(item) == RETURNVALUE_NOERROR) {
++removeCount;
}
}
} else {
it++;
}
}
if (removeCount > 0) {
g_game().addMagicEffect(tile->getPosition(), CONST_ME_POFF);
if (removeCount > 0) {
g_game().addMagicEffect(tile->getPosition(), CONST_ME_POFF);
}
}
}

Expand Down

0 comments on commit fa85e18

Please sign in to comment.