From 81a02c14b6b4fa271a4fd4a8707eb2eddb089917 Mon Sep 17 00:00:00 2001 From: murilo09 <78226931+murilo09@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:04:31 -0300 Subject: [PATCH] fix: increasing reference counter --- src/creatures/monsters/monster.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 044abdb3494..8cdac980134 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -669,7 +669,8 @@ bool Monster::isOpponent(const std::shared_ptr &creature) const { return creature != master; } - if (creature->getPlayer() && creature->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByMonsters)) { + const auto &player = creature ? creature->getPlayer() : nullptr; + if (player && player->hasFlag(PlayerFlags_t::IgnoredByMonsters)) { return false; } @@ -679,7 +680,7 @@ bool Monster::isOpponent(const std::shared_ptr &creature) const { const auto &creatureMaster = creature->getMaster(); const auto &creaturePlayer = creatureMaster ? creatureMaster->getPlayer() : nullptr; - if (creature->getPlayer() || creaturePlayer) { + if (player || creaturePlayer) { return true; } @@ -913,7 +914,8 @@ bool Monster::isTarget(const std::shared_ptr &creature) { } if (!isSummon()) { - if (creature->getPlayer() && creature->getPlayer()->isDisconnected()) { + const auto &player = creature ? creature->getPlayer() : nullptr; + if (player && player->isDisconnected()) { return false; } @@ -934,7 +936,8 @@ bool Monster::selectTarget(const std::shared_ptr &creature) { return false; } - if (creature && creature->getPlayer()->isLoginProtected()) { + const auto &player = creature ? creature->getPlayer() : nullptr; + if (player && player->isLoginProtected()) { return false; }