Skip to content

Commit

Permalink
Vehicle: Add an explicit cleanup routine outside of destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 3, 2025
1 parent 11357b5 commit 85ee8f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12391,7 +12391,11 @@ void Unit::SetVehicleId(uint32 entry, uint32 overwriteNpcEntry)
if (m_vehicleInfo && entry == m_vehicleInfo->GetVehicleEntry()->m_ID)
return;

m_vehicleInfo = nullptr;
if (m_vehicleInfo)
{
m_vehicleInfo->Cleanup();
m_vehicleInfo = nullptr;
}

if (entry)
{
Expand Down
16 changes: 12 additions & 4 deletions src/game/Entities/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ VehicleInfo::VehicleInfo(Unit* owner, VehicleEntry const* vehicleEntry, uint32 o
m_overwriteNpcEntry(overwriteNpcEntry),
m_isInitialized(false),
m_disabledAccessoryInit(false),
m_originalFaction(owner->GetFaction())
m_originalFaction(owner->GetFaction()),
m_cleanedUp(false)
{
MANGOS_ASSERT(vehicleEntry);

Expand All @@ -197,9 +198,7 @@ VehicleInfo::VehicleInfo(Unit* owner, VehicleEntry const* vehicleEntry, uint32 o

VehicleInfo::~VehicleInfo()
{
((Unit*)m_owner)->RemoveSpellsCausingAura(SPELL_AURA_CONTROL_VEHICLE);

RemoveAccessoriesFromMap(); // Remove accessories (for example required with player vehicles)
MANGOS_ASSERT(m_cleanedUp);

This comment has been minimized.

Copy link
@kelbren

kelbren Jan 4, 2025

Server crashes every few minutes, commenting the assert out stops the crashes. probably needs more investigation.

This comment has been minimized.

Copy link
@killerwife

killerwife Jan 4, 2025

Author Contributor

Thats by design so that ppl post the crash logs.

}

void VehicleInfo::Initialize()
Expand Down Expand Up @@ -248,6 +247,15 @@ void VehicleInfo::Initialize()
m_isInitialized = true;
}

void VehicleInfo::Cleanup()
{
((Unit*)m_owner)->RemoveSpellsCausingAura(SPELL_AURA_CONTROL_VEHICLE);

RemoveAccessoriesFromMap(); // Remove accessories (for example required with player vehicles)

m_cleanedUp = true;
}

void VehicleInfo::SummonPassenger(uint32 entry, Position const& pos, uint8 seatId)
{
if (Creature* summoned = m_owner->SummonCreature(entry, pos.x, pos.y, pos.z, pos.o, TEMPSPAWN_DEAD_DESPAWN, 0))
Expand Down
2 changes: 2 additions & 0 deletions src/game/Entities/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class VehicleInfo : public TransportBase
public:
explicit VehicleInfo(Unit* owner, VehicleEntry const* vehicleEntry, uint32 overwriteNpcEntry);
void Initialize(); ///< Initializes the accessories
void Cleanup();
bool IsInitialized() const { return m_isInitialized; }
void SummonPassenger(uint32 entry, Position const& pos, uint8 seatId);

Expand Down Expand Up @@ -139,6 +140,7 @@ class VehicleInfo : public TransportBase
uint32 m_originalFaction; // Internal use to store the original unit faction before taking control of the unit
GuidSet m_accessoryGuids; // Stores the summoned accessories of this vehicle
std::vector<std::pair<ObjectGuid, uint8>> m_unboardedAccessories; // Stores unboarded accessories for purpose of recall
bool m_cleanedUp;
};

#endif
Expand Down

0 comments on commit 85ee8f1

Please sign in to comment.