Skip to content

Game can crash if AIGroup list is cleared while iterating over it in AIGroup::groupDoSpecialPowerAtLocation #3185

Description

@Caball009

void AIGroup::groupDoSpecialPowerAtLocation( UnsignedInt specialPowerID, const Coord3D *location, Real angle, const Object *objectInWay, UnsignedInt commandOptions )
{
//This one requires a position
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); )
{
//Special powers do a lot of different things, but the top level stuff doesn't use
//ai interface code. It finds the special power module and calls it directly for each object.
Object *object = (*i);
++i; // just in case the act of specialpowering changes this list,
// like when the rebelambush happens over the ocean, and all the rebels drown
// and, of course, their slowdeath behavior calls deselect(), which naturally
// destroys the AIGroup list, in order to keep the selection sync'ed with the group.
// M Lorenzen... 8/23/03

The last comment acknowledges that the AIGroup list can be destroyed by calling the GLA Rebel Ambush at an invalid location. In that case m_memberList would be empty after the call to doSpecialPowerAtLocation (line 2753).

If this occurs a couple of things can happen:

  1. One item in m_memberList:
  • VS22 Debug build: MSVC iterator assertion ("list iterators incompatible").
  • VS22 / VC6 Release builds: no apparent issue.
  1. Two or more items in m_memberList (probably unlikely to happen):
  • VS22 Debug build: MSVC iterator assertion ("list iterators incompatible").
  • VS22 / VC6 Release builds: game crashes.

VS22 Debug iterator assertion reproduction:

  1. Select GLA Command Center and use it to call in GLA Rebel Ambush in on invalid location like steep terrain or water.
  2. Be sure to use the special power button from the Command Center.

Crash reproduction (requires code changes):

  1. Build two GLA Command Centers.
  2. Select both (disable or skip our selection fixes that prevent this) and keep both selected.
  3. Call in GLA Rebel Ambush in on invalid location like steep terrain or water.
  4. Set 6th argument for MSG_DO_SPECIAL_POWER_AT_LOCATION to INVALID_ID.

Here's a custom map and VS22 replay, which also works for VC6, that crashes the game because of this bug: vs22_special_power_selection_crash.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working right, typically is user facingCrashThis is a crash, very bad

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions