diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index d3dbb67e24b..70ac05b3f2b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -2889,11 +2889,12 @@ void AIGroup::groupDoCommandButton( const CommandButton *commandButton, CommandS std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButton( commandButton, cmdSource ); } @@ -2909,11 +2910,12 @@ void AIGroup::groupDoCommandButtonAtPosition( const CommandButton *commandButton std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButtonAtPosition( commandButton, pos, cmdSource ); } @@ -2928,11 +2930,12 @@ void AIGroup::groupDoCommandButtonAtObject( const CommandButton *commandButton, std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButtonAtObject( commandButton, obj, cmdSource ); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index effcd157c50..17f7b045bc1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -2962,11 +2962,12 @@ void AIGroup::groupDoCommandButton( const CommandButton *commandButton, CommandS std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButton( commandButton, cmdSource ); } @@ -2982,11 +2983,12 @@ void AIGroup::groupDoCommandButtonAtPosition( const CommandButton *commandButton std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButtonAtPosition( commandButton, pos, cmdSource ); } @@ -3001,11 +3003,12 @@ void AIGroup::groupDoCommandButtonUsingWaypoints( const CommandButton *commandBu std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButtonUsingWaypoints( commandButton, way, cmdSource ); } @@ -3020,11 +3023,12 @@ void AIGroup::groupDoCommandButtonAtObject( const CommandButton *commandButton, std::list::iterator i; Object *source; - for( i = m_memberList.begin(); i != m_memberList.end(); ++i ) + for( i = m_memberList.begin(); i != m_memberList.end(); /* empty */ ) { // get object source = *i; + ++i; // Advance iterator before the call that might destroy the object source->doCommandButtonAtObject( commandButton, obj, cmdSource ); }