File tree Expand file tree Collapse file tree
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain
Generals/Code/GameEngine/Source/GameLogic/Object/Contain Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,15 +254,13 @@ void OverlordContain::removeAllContained( Bool exposeStealthUnits )
254254 return ;
255255 }
256256
257- const ContainedItemsList *fullList = getRedirectedContain ()->getContainedItemsList ();
258-
259- Object *obj;
260- ContainedItemsList::const_iterator it;
261- it = (*fullList).begin ();
262- while ( it != (*fullList).end () )
257+ // Use a safe iterator pattern to avoid iterator invalidation.
258+ // Always get a fresh iterator from the beginning after each removal,
259+ // similar to OpenContain::removeAllContained()
260+ const ContainedItemsList *fullList;
261+ while ( (fullList = getRedirectedContain ()->getContainedItemsList ()) != NULL && !fullList->empty () )
263262 {
264- obj = *it;
265- it++;
263+ Object *obj = fullList->front ();
266264 removeFromContain ( obj, exposeStealthUnits );
267265 }
268266}
Original file line number Diff line number Diff line change @@ -328,15 +328,13 @@ void OverlordContain::removeAllContained( Bool exposeStealthUnits )
328328 return ;
329329 }
330330
331- const ContainedItemsList *fullList = getRedirectedContain ()->getContainedItemsList ();
332-
333- Object *obj;
334- ContainedItemsList::const_iterator it;
335- it = (*fullList).begin ();
336- while ( it != (*fullList).end () )
331+ // Use a safe iterator pattern to avoid iterator invalidation.
332+ // Always get a fresh iterator from the beginning after each removal,
333+ // similar to OpenContain::removeAllContained()
334+ const ContainedItemsList *fullList;
335+ while ( (fullList = getRedirectedContain ()->getContainedItemsList ()) != NULL && !fullList->empty () )
337336 {
338- obj = *it;
339- it++;
337+ Object *obj = fullList->front ();
340338 removeFromContain ( obj, exposeStealthUnits );
341339 }
342340}
You can’t perform that action at this time.
0 commit comments