Skip to content

Commit

Permalink
Fix #386: NRE downstream from OnLoad
Browse files Browse the repository at this point in the history
-need to cache KSPField references in OnAwake instead of OnStart because other code can call functions that use them before the module has been started
  • Loading branch information
JonnyOThan committed Feb 22, 2025
1 parent da45897 commit 2cf335e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions SCANsat/SCAN_PartModules/SCANresourceDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ public float MaxAbundanceAltitude
get { return maxAbundanceAltitude; }
}

public override void OnAwake()
{
base.OnAwake();
abundanceField = Fields["abundance"];
}

public override void OnStart(PartModule.StartState state)
{
if (state == StartState.Editor)
{
return;
}

abundanceField = Fields["abundance"];

GameEvents.onVesselSOIChanged.Add(onSOIChange);

part.force_activate();
Expand Down
9 changes: 6 additions & 3 deletions SCANsat/SCAN_PartModules/SCANsat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ public bool scanningNow

protected bool UpdateScannerInfo = true;

/* SAT: KSP entry points */
public override void OnStart(StartState state)
public override void OnAwake()
{
base.OnAwake();
scanInfoStatus = Fields["scanStatus"];
scanInfoAltitude = Fields["scanAltitude"];
scanInfoType = Fields["scanType"];
scanInfoFOV = Fields["scanFOV"];
scanInfoPower = Fields["scanPower"];
scanInfoDaylight = Fields["scanDaylight"];
}


/* SAT: KSP entry points */
public override void OnStart(StartState state)
{
if (state == StartState.Editor)
{
print("[SCANsat] start: in editor");
Expand Down

0 comments on commit 2cf335e

Please sign in to comment.