diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 8787efb4..54a3ef6e 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -17540,12 +17540,30 @@ void Player::UpdateQuestObjectiveProgress(QuestObjectiveType objectiveType, int3
}
}
+ // Collect the matching quest/objective ids before touching any quest state. A completed objective can
+ // immediately pay out and remove a world quest (Player::CompleteQuest -> RewardQuest ->
+ // RemoveActiveQuest), which erases entries from both m_questObjectiveStatus and m_QuestStatus. Holding
+ // iterators into either container across that call leaves dangling iterators in the loop (crash in
+ // Player::UpdateQuestObjectiveProgress when the next kill credit is processed).
+ std::vector> matchingObjectives;
for (QuestObjectiveStatusMap::value_type const& objectiveItr : Trinity::Containers::MapEqualRange(m_questObjectiveStatus, { objectiveType, objectId }))
{
if (objectiveItr.second.QuestStatusItr == m_QuestStatus.end())
continue;
- uint32 questId = objectiveItr.second.QuestStatusItr->first;
+ matchingObjectives.emplace_back(objectiveItr.second.QuestStatusItr->first, objectiveItr.second.ObjectiveId);
+ }
+
+ for (std::pair const& objectiveRef : matchingObjectives)
+ {
+ uint32 questId = objectiveRef.first;
+
+ // Re-resolve the quest status for every entry: an earlier objective of this same update may have
+ // completed and removed the quest (world quest payout) or a script may have changed it.
+ auto questStatusItr = m_QuestStatus.find(questId);
+ if (questStatusItr == m_QuestStatus.end())
+ continue;
+
Quest const* quest = sObjectMgr->GetQuestTemplate(questId);
if (!quest)
continue;
@@ -17554,8 +17572,8 @@ void Player::UpdateQuestObjectiveProgress(QuestObjectiveType objectiveType, int3
if (GetGroup() && GetGroup()->isRaidGroup() && !quest->IsAllowedInRaid(GetMap()->GetDifficultyID()))
continue;
- uint16 logSlot = objectiveItr.second.QuestStatusItr->second.Slot;
- QuestObjective const* objective = sObjectMgr->GetQuestObjective(objectiveItr.second.ObjectiveId);
+ uint16 logSlot = questStatusItr->second.Slot;
+ QuestObjective const* objective = sObjectMgr->GetQuestObjective(objectiveRef.second);
if (!objective || !IsQuestObjectiveCompletable(logSlot, quest, *objective))
continue;
@@ -17660,7 +17678,7 @@ void Player::UpdateQuestObjectiveProgress(QuestObjectiveType objectiveType, int3
if (objective->ID == spawnTrackingQuestObjectiveId)
{
// Store spawn tracking to return correct state in Player::GetSpawnTrackingStateByObjective
- QuestStatusData& questStatus = objectiveItr.second.QuestStatusItr->second;
+ QuestStatusData& questStatus = questStatusItr->second;
questStatus.SpawnTrackingList.insert(std::make_pair(objective->StorageIndex, data->spawnTrackingData->SpawnTrackingId));
// Send QuestPOIUpdateResponse for every spawn linked to same SpawnTrackingId
@@ -17712,7 +17730,7 @@ void Player::UpdateQuestObjectiveProgress(QuestObjectiveType objectiveType, int3
if (CanCompleteQuest(questId, objective->ID))
CompleteQuest(questId);
}
- else if (!(objective->Flags & QUEST_OBJECTIVE_FLAG_OPTIONAL) && objectiveItr.second.QuestStatusItr->second.Status == QUEST_STATUS_COMPLETE)
+ else if (!(objective->Flags & QUEST_OBJECTIVE_FLAG_OPTIONAL) && questStatusItr->second.Status == QUEST_STATUS_COMPLETE)
IncompleteQuest(questId);
if (updatedObjectives)