Skip to content

Commit 25bd33e

Browse files
authored
[GEN][ZH] Fix game crash in AIGroup::groupSell() (#1200)
1 parent a8c703f commit 25bd33e

File tree

2 files changed

+22
-26
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameLogic/AI
  • Generals/Code/GameEngine/Source/GameLogic/AI

2 files changed

+22
-26
lines changed

Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,23 +2722,21 @@ void AIGroup::groupCheer( CommandSourceType cmdSource )
27222722
*/
27232723
void AIGroup::groupSell( CommandSourceType cmdSource )
27242724
{
2725-
std::list<Object *>::iterator i, thisIterator;
2726-
Object *obj;
2725+
std::list<Object *>::iterator i;
2726+
std::vector<Object *> groupObjectsCopy;
2727+
groupObjectsCopy.reserve(m_memberListSize);
27272728

2729+
// TheSuperHackers @bugfix Mauller 26/06/2025 when sellObject is called, the member list objects in this AIGroup get removed from it. This happens within the Object::deselectObject() function.
2730+
// This deletes the local AIGroup object from under the call to groupSell, therefore we need to make a local copy of the objects that need selling.
27282731
for( i = m_memberList.begin(); i != m_memberList.end(); /*empty*/ )
27292732
{
2733+
groupObjectsCopy.push_back( *i++ );
2734+
}
27302735

2731-
// work off of 'thisIterator' as we may change the contents of this list
2732-
thisIterator = i;
2733-
++i;
2734-
2735-
// get object
2736-
obj = *thisIterator;
2737-
2738-
// try to sell object
2739-
TheBuildAssistant->sellObject( obj );
2740-
2741-
} // end for, i
2736+
for( size_t j = 0; j < groupObjectsCopy.size(); ++j )
2737+
{
2738+
TheBuildAssistant->sellObject( groupObjectsCopy[j] );
2739+
}
27422740

27432741
}
27442742

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,23 +2795,21 @@ void AIGroup::groupCheer( CommandSourceType cmdSource )
27952795
*/
27962796
void AIGroup::groupSell( CommandSourceType cmdSource )
27972797
{
2798-
std::list<Object *>::iterator i, thisIterator;
2799-
Object *obj;
2798+
std::list<Object *>::iterator i;
2799+
std::vector<Object *> groupObjectsCopy;
2800+
groupObjectsCopy.reserve(m_memberListSize);
28002801

2802+
// TheSuperHackers @bugfix Mauller 26/06/2025 when sellObject is called, the member list objects in this AIGroup get removed from it. This happens within the Object::deselectObject() function.
2803+
// This deletes the local AIGroup object from under the call to groupSell, therefore we need to make a local copy of the objects that need selling.
28012804
for( i = m_memberList.begin(); i != m_memberList.end(); /*empty*/ )
28022805
{
2806+
groupObjectsCopy.push_back( *i++ );
2807+
}
28032808

2804-
// work off of 'thisIterator' as we may change the contents of this list
2805-
thisIterator = i;
2806-
++i;
2807-
2808-
// get object
2809-
obj = *thisIterator;
2810-
2811-
// try to sell object
2812-
TheBuildAssistant->sellObject( obj );
2813-
2814-
} // end for, i
2809+
for( size_t j = 0; j < groupObjectsCopy.size(); ++j )
2810+
{
2811+
TheBuildAssistant->sellObject( groupObjectsCopy[j] );
2812+
}
28152813

28162814
}
28172815

0 commit comments

Comments
 (0)