Skip to content

Commit 2cf335e

Browse files
committed
Fix #386: NRE downstream from OnLoad
-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
1 parent da45897 commit 2cf335e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

SCANsat/SCAN_PartModules/SCANresourceDisplay.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ public float MaxAbundanceAltitude
5959
get { return maxAbundanceAltitude; }
6060
}
6161

62+
public override void OnAwake()
63+
{
64+
base.OnAwake();
65+
abundanceField = Fields["abundance"];
66+
}
67+
6268
public override void OnStart(PartModule.StartState state)
6369
{
6470
if (state == StartState.Editor)
6571
{
6672
return;
6773
}
6874

69-
abundanceField = Fields["abundance"];
70-
7175
GameEvents.onVesselSOIChanged.Add(onSOIChange);
7276

7377
part.force_activate();

SCANsat/SCAN_PartModules/SCANsat.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@ public bool scanningNow
8484

8585
protected bool UpdateScannerInfo = true;
8686

87-
/* SAT: KSP entry points */
88-
public override void OnStart(StartState state)
87+
public override void OnAwake()
8988
{
89+
base.OnAwake();
9090
scanInfoStatus = Fields["scanStatus"];
9191
scanInfoAltitude = Fields["scanAltitude"];
9292
scanInfoType = Fields["scanType"];
9393
scanInfoFOV = Fields["scanFOV"];
9494
scanInfoPower = Fields["scanPower"];
9595
scanInfoDaylight = Fields["scanDaylight"];
96+
}
9697

97-
98+
/* SAT: KSP entry points */
99+
public override void OnStart(StartState state)
100+
{
98101
if (state == StartState.Editor)
99102
{
100103
print("[SCANsat] start: in editor");

0 commit comments

Comments
 (0)