From b08d85349c54e524e7d52c2acc9e9c367b61afaf Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 8 Jul 2024 11:23:41 +0200 Subject: Core/Creatures: Fixed memory leaks in creature formations (cherry picked from commit 2e3920081f4f349a226ab5238cd983403e167656) --- src/server/game/Entities/Unit/Unit.cpp | 6 +++--- src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 94cdf8c3118..8fb57bafe9e 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -12637,11 +12637,11 @@ void Unit::_EnterVehicle(Vehicle* vehicle, int8 seatId, AuraApplication const* a return; } - if (vehicle->GetBase()->GetTypeId() == TYPEID_UNIT) + if (Creature* vehicleBaseCreature = vehicle->GetBase()->ToCreature()) { // If a player entered a vehicle that is part of a formation, remove it from said formation - if (CreatureGroup* creatureGroup = vehicle->GetBase()->ToCreature()->GetFormation()) - creatureGroup->RemoveMember(vehicle->GetBase()->ToCreature()); + if (CreatureGroup* creatureGroup = vehicleBaseCreature->GetFormation()) + sFormationMgr->RemoveCreatureFromGroup(creatureGroup, vehicleBaseCreature); } } diff --git a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp index 009af793d19..afb6083047e 100644 --- a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp +++ b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp @@ -114,8 +114,8 @@ struct npc_cameron : public ScriptedAI // first we break formation because children will need to move on their own now for (auto guid : _childrenGUIDs) if (Creature* child = ObjectAccessor::GetCreature(*me, guid)) - if (child->GetFormation()) - child->GetFormation()->RemoveMember(child); + if (CreatureGroup* creatureGroup = child->GetFormation()) + sFormationMgr->RemoveCreatureFromGroup(creatureGroup, child); // Move each child to an random position for (uint32 i = 0; i < _childrenGUIDs.size(); ++i) -- cgit v1.2.3