Following is the result of my analysis.
I generated a PR adding following line to MSTSLocomotive.InitializeMoving()
EngineBrakeController?.SetPercent(0);
This caused no problems.
I was asked to correct this to
EngineBrakeController?.InitializeMoving();
This causes a crash when in the player train there is a non-leading locomotive with no controllers set in the .eng file, and when a switch to autopilot is performed.
The crash starts from following line in AITrain.SwitchToAutopilotControl()
if (loco.EngineBrakeController != null) loco.SetEngineBrakePercent(0);
The crash occurs in MSTSNotchController.SetPercent(percent), because EngineBrakeController.CurrentNotch was set to 0 by EngineBrakeController.InitializeMoving(), and so within these lines of MSTSNotchControllerSetPercent(percent)
if (CurrentNotch >= 0) { if (Notches[Notches.Count - 1].Type == ControllerState.Emergency)
Notches[Notches.Count - 1] fails because there are 0 notches.
In the original solution instead CurrentNotch remains to -1 and so the second "if" is not executed.
A fix within MSTSBrakeController.InitializeMoving() is being introduced that checks for the number of notches before setting CurrentNotch to zero.
BTW OR seems to generate controllers with zero notches also for locomotives with no controllers defined in the .eng file.