fix: invoke despawn callbacks on disconnect to prevent renderer leaks

Mirror the zone-transition cleanup in disconnect(): fire despawn callbacks
for all entities before clearing the entity manager. Prevents M2 instances
and character models from leaking when the player disconnects and reconnects
quickly (e.g., server kick, network recovery).
This commit is contained in:
Kelsi 2026-03-20 18:07:00 -07:00
parent 922177abe0
commit ff1840415e

View file

@ -784,7 +784,22 @@ void GameHandler::disconnect() {
wardenLoadedModule_.reset();
pendingIncomingPackets_.clear();
pendingUpdateObjectWork_.clear();
// Clear entity state so reconnect sees fresh CREATE_OBJECT for all visible objects.
// Fire despawn callbacks so the renderer releases M2/character model resources.
for (const auto& [guid, entity] : entityManager.getEntities()) {
if (guid == playerGuid) continue;
if (entity->getType() == ObjectType::UNIT && creatureDespawnCallback_)
creatureDespawnCallback_(guid);
else if (entity->getType() == ObjectType::PLAYER && playerDespawnCallback_)
playerDespawnCallback_(guid);
else if (entity->getType() == ObjectType::GAMEOBJECT && gameObjectDespawnCallback_)
gameObjectDespawnCallback_(guid);
}
otherPlayerVisibleItemEntries_.clear();
otherPlayerVisibleDirty_.clear();
otherPlayerMoveTimeMs_.clear();
unitCastStates_.clear();
unitAurasCache_.clear();
combatText.clear();
entityManager.clear();
setState(WorldState::DISCONNECTED);
LOG_INFO("Disconnected from world server");