diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 1ee432568c2..4bb528e6c12 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -434,17 +434,26 @@ void OpenContain::removeAllContained( Bool exposeStealthUnits ) //------------------------------------------------------------------------------------------------- void OpenContain::killAllContained( void ) { - ContainedItemsList::iterator it = m_containList.begin(); + // TheSuperHackers @bugfix xezon 23/05/2025 Empty m_containList straight away + // to prevent a potential child call to catastrophically modify the m_containList as well. + // This scenario can happen if the killed occupant(s) apply deadly damage on death + // to the host container, which then attempts to remove all remaining occupants + // on the death of the host container. This is reproducible by shooting with + // Neutron Shells on a GLA Technical containing GLA Terrorists. + ContainedItemsList list; + list.swap(m_containList); + m_containListSize = 0; - while ( it != m_containList.end() ) + ContainedItemsList::iterator it = list.begin(); + + while ( it != list.end() ) { Object *rider = *it; - + DEBUG_ASSERTCRASH( rider, ("Contain list must not contain NULL element")); if ( rider ) { - it = m_containList.erase(it); - m_containListSize--; + it = list.erase(it); onRemoving( rider ); rider->onRemovedFrom( getObject() ); @@ -459,7 +468,7 @@ void OpenContain::killAllContained( void ) DEBUG_ASSERTCRASH( m_containListSize == 0, ("killallcontain just made a booboo, list size != zero.") ); -} // end removeAllContained +} // end killAllContained //-------------------------------------------------------------------------------------------------------- /** Force all contained objects in the contained list to exit, and kick them in the pants on the way out*/ @@ -472,6 +481,7 @@ void OpenContain::harmAndForceExitAllContained( DamageInfo *info ) { Object *rider = *it; + DEBUG_ASSERTCRASH( rider, ("Contain list must not contain NULL element")); if ( rider ) { removeFromContain( rider, true ); @@ -490,7 +500,7 @@ void OpenContain::harmAndForceExitAllContained( DamageInfo *info ) DEBUG_ASSERTCRASH( m_containListSize == 0, ("harmAndForceExitAllContained just made a booboo, list size != zero.") ); -} // end removeAllContained +} // end harmAndForceExitAllContained //-------------------------------------------------------------------------------------------------