RemoveWaypoint throws collection modified error

BDCarrillo shared this bug 3 months ago
Investigating

Calling RemoveWaypoint on a MyBasicMissionAutopilot throws a System.InvalidOperationException since the collection is modified. The subject code is below- seems the raised event is altering the m_waypoints collection while it's still being iterated.


		public void RemoveWaypoint(IMyAutopilotWaypoint waypoint)
		{
			foreach (MyAutopilotWaypoint waypoint2 in m_waypoints)
			{
				if (waypoint == waypoint2)
				{
					MyMultiplayer.RaiseEvent(this, (MyBasicMissionAutopilot x) => x.RemoveWaypoints, new int[1] { m_waypoints.IndexOf(waypoint2) });
				}
			}
		}

Leave a Comment
 
Attach a file