diff --git a/SCANsat/SCAN_Data/SCANdata.cs b/SCANsat/SCAN_Data/SCANdata.cs index c21d70b94..afb70b495 100644 --- a/SCANsat/SCAN_Data/SCANdata.cs +++ b/SCANsat/SCAN_Data/SCANdata.cs @@ -201,6 +201,9 @@ public SCANanomaly[] Anomalies public List ROCS(bool refresh) { + if (ROCManager.Instance == null) + return null; + if (!ROCManager.Instance.RocsEnabledInCurrentGame) return null; @@ -215,15 +218,21 @@ public List ROCS(bool refresh) rocs.Clear(); + if (body == null) + return null; + PQS controller = body.pqsController; - if (controller == null) + if (controller == null || controller.transform == null) return null; for (int i = controller.transform.childCount - 1; i >= 0; i--) { Transform child = controller.transform.GetChild(i); + if (child == null) + continue; + if (child.name.StartsWith("ROC")) { int index = child.name.IndexOf(' '); @@ -232,16 +241,26 @@ public List ROCS(bool refresh) { string id = child.name.Substring(index + 1); - List subjects = ResearchAndDevelopment.GetSubjects(); - bool scanned = false; - for (int k = subjects.Count - 1; k >= 0; k--) + if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || HighLogic.CurrentGame.Mode == Game.Modes.MISSION) + { + scanned = true; + } + else { - if (subjects[k].id.Contains(id)) + List subjects = ResearchAndDevelopment.GetSubjects(); + + if (subjects != null) { - scanned = true; - break; + for (int k = subjects.Count - 1; k >= 0; k--) + { + if (subjects[k].id.Contains(id)) + { + scanned = true; + break; + } + } } } @@ -249,6 +268,9 @@ public List ROCS(bool refresh) { Transform cache = child.GetChild(j); + if (cache == null) + continue; + if (cache.name != ("Unassigned")) { ROC roc = cache.GetComponentInChildren();