-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Steps to Reproduce
Summary: SharedVisionList Iterator Invalidation Crash
The Crash
Signal: SIGSEGV (Segmentation Fault)
Location: GridNotifiers.cpp:121 in VisibleChangesNotifier::Visit(CreatureMapType&)
Error: i = non-dereferenceable iterator for std::list
Root Cause
The code was calling GetSharedVisionList().begin() once and GetSharedVisionList().end() on every loop iteration:
for (SharedVisionList::const_iterator i = iter->GetSource()->GetSharedVisionList().begin(); i != iter->GetSource()->GetSharedVisionList().end(); ++i) // end() called each iteration! if ((*i)->m_seer == iter->GetSource()) (*i)->UpdateVisibilityOf(&i_object); // Can modify the SharedVisionList!
When UpdateVisibilityOf() indirectly modifies the SharedVisionList (adding/removing players), the iterator i becomes invalidated, causing a crash on the next dereference.
Logs and Screenshots
Operating System
Debian 12
Dependencies & versions
Commit
Additional Context
IA Claude suggestion:
Create a local copy of the list before iterating:
SharedVisionList sharedVisionCopy = iter->GetSource()->GetSharedVisionList();
for (Player* player : sharedVisionCopy)
{
if (player && player->m_seer == iter->GetSource())
player->UpdateVisibilityOf(&i_object);
}