Summary
When FirstPersonEVA.Update() calls EVABoundFix.Hook(eva) after a vessel switch, the EVABoundFix constructor throws a NullReferenceException if any of the KFSM fields it touches are still null on that KerbalEVA instance. Because Update() re-attempts the hook every frame, the exception is logged 50+ times per second.
In long sessions this produces 200+ MB KSP.log files and contributes to Mono GC mark-stack overflow crashes.
Repro stack
NullReferenceException: Object reference not set to an instance of an object
FirstPerson.EVABoundFix..ctor (KerbalEVA eva)
FirstPerson.EVABoundFix.Hook (KerbalEVA eva)
FirstPerson.FirstPersonEVA.Update ()
Source
EVABoundFix.cs lines 20–62:
EVABoundFix(KerbalEVA eva)
{
myeva = eva;
ReflectedMembers.Initialize();
myeva.On_bound_fall.OnCheckCondition = ...; // NRE if On_bound_fall is null
myeva.On_bound_land.OnCheckCondition = ...; // NRE if On_bound_land is null
for (int i = 0; i < myeva.st_bound_fl.StateEvents.Count; ++i) // NRE if st_bound_fl null
...
}
Some custom EVA suits / mod-added KerbalEVAs initialize these fields lazily (or not at all), so the constructor hits a null reference. Since FirstPersonEVA.Update() doesn't track failed hooks, it tries again every frame.
Suggested fix
Either guard each access in the constructor, or have Hook validate the relevant fields before constructing:
public static void Hook(KerbalEVA eva)
{
if (eva == null || eva.vessel == null) return;
if (eva.On_bound_fall == null || eva.On_bound_land == null || eva.st_bound_fl == null) return;
new EVABoundFix(eva);
}
It might also be worth tracking which KerbalEVA instances were successfully hooked so Update() doesn't retry them on every frame.
Workaround
Standalone Harmony Prefix that validates the fields before Hook runs and skips with deduplicated logging:
https://github.com/edujoliver/TTE-Fix
Happy to send a PR if useful.
Environment
- KSP 1.12.5
- Through-The-Eyes 2.0.4.5
- KSPCommunityFixes 1.39.1
Summary
When
FirstPersonEVA.Update()callsEVABoundFix.Hook(eva)after a vessel switch, theEVABoundFixconstructor throws aNullReferenceExceptionif any of the KFSM fields it touches are still null on thatKerbalEVAinstance. BecauseUpdate()re-attempts the hook every frame, the exception is logged 50+ times per second.In long sessions this produces 200+ MB
KSP.logfiles and contributes to Mono GC mark-stack overflow crashes.Repro stack
Source
EVABoundFix.cslines 20–62:Some custom EVA suits / mod-added KerbalEVAs initialize these fields lazily (or not at all), so the constructor hits a null reference. Since
FirstPersonEVA.Update()doesn't track failed hooks, it tries again every frame.Suggested fix
Either guard each access in the constructor, or have
Hookvalidate the relevant fields before constructing:It might also be worth tracking which
KerbalEVAinstances were successfully hooked soUpdate()doesn't retry them on every frame.Workaround
Standalone Harmony Prefix that validates the fields before
Hookruns and skips with deduplicated logging:https://github.com/edujoliver/TTE-Fix
Happy to send a PR if useful.
Environment