From 2947a7b342f722142196f8ecc8830a75f598ca8b Mon Sep 17 00:00:00 2001 From: Codinablack Date: Thu, 31 Oct 2024 23:15:49 -0500 Subject: [PATCH 1/3] Fix memory leak in spawns When we spawn a monster, we increment the count on the monster object for the entry into the spawnedmap. When we remove the monster from the spawnedmap because of it being outside the zone, we don't decrement the ref count, which leads to a leak. There is also extra logic in place for a spawn ID 0. Not sure why monsters were being removed from the spawned map and placed back into it with 0 as the id for when they leave the area, but I find no other interactions or checks for spawn id being 0, so there seems to be zero reason, and whatever was so special about spawn id 0 doesn't exist anymore, so I cleaned up that old code that has not been in use since apparently before TFS was TFS. --- src/spawn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spawn.cpp b/src/spawn.cpp index a744e58793..0972db313b 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -394,8 +394,8 @@ void Spawn::cleanup() if (monster->isRemoved()) { monster->decrementReferenceCounter(); it = spawnedMap.erase(it); - } else if (!isInSpawnZone(monster->getPosition()) && spawnId != 0) { - spawnedMap.insert({0, monster}); + } else if (!isInSpawnZone(monster->getPosition())) { + monster->decrementReferenceCounter(); it = spawnedMap.erase(it); } else { ++it; From 7d36a23a8f42895f4386818bb3bf35ad8dbecea6 Mon Sep 17 00:00:00 2001 From: Codinablack Date: Thu, 31 Oct 2024 23:40:40 -0500 Subject: [PATCH 2/3] Removed unused spawnID variable --- src/spawn.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/spawn.cpp b/src/spawn.cpp index 0972db313b..d6eb6944a6 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -389,7 +389,6 @@ void Spawn::cleanup() { auto it = spawnedMap.begin(); while (it != spawnedMap.end()) { - uint32_t spawnId = it->first; Monster* monster = it->second; if (monster->isRemoved()) { monster->decrementReferenceCounter(); From 98caf96b0c6cd93764a46cd7a6d69bfdf8448e3f Mon Sep 17 00:00:00 2001 From: Codinablack Date: Fri, 1 Nov 2024 00:47:52 -0500 Subject: [PATCH 3/3] Fix overspawn problem and remove unused method --- src/spawn.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/spawn.cpp b/src/spawn.cpp index d6eb6944a6..11cd78694c 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -271,8 +271,6 @@ bool Spawn::findPlayer(const Position& pos) return false; } -bool Spawn::isInSpawnZone(const Position& pos) { return Spawns::isInZone(centerPos, radius, pos); } - bool Spawn::spawnMonster(uint32_t spawnId, spawnBlock_t sb, bool startup /* = false*/) { bool isBlocked = !startup && findPlayer(sb.pos); @@ -393,9 +391,6 @@ void Spawn::cleanup() if (monster->isRemoved()) { monster->decrementReferenceCounter(); it = spawnedMap.erase(it); - } else if (!isInSpawnZone(monster->getPosition())) { - monster->decrementReferenceCounter(); - it = spawnedMap.erase(it); } else { ++it; }