Skip to content

Commit

Permalink
Fix NullReferenceException spam when a kerbal goes on EVA
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Apr 24, 2017
1 parent c103f99 commit 78af4b1
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetwork.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommNet;
using System;

namespace CommNetConstellation.CommNetLayer
{
Expand All @@ -14,17 +15,37 @@ public class CNCCommNetwork : CommNetwork
/// </summary>
protected override bool SetNodeConnection(CommNode a, CommNode b)
{
short aFreq = (a.isHome)? publicFreq : ((CNCCommNetVessel) CNCCommNetScenario.Instance.findCorrespondingVessel(a).Connection).getRadioFrequency();
short bFreq = (b.isHome)? publicFreq : ((CNCCommNetVessel) CNCCommNetScenario.Instance.findCorrespondingVessel(b).Connection).getRadioFrequency();
short aFreq, bFreq;

try
{
aFreq = (a.isHome) ? publicFreq : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(a).Connection).getRadioFrequency();
bFreq = (b.isHome) ? publicFreq : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(b).Connection).getRadioFrequency();
}
catch(NullReferenceException e) // either CommNode could be a kerbal on EVA
{
this.Disconnect(a, b, true);
return false;
}

if (aFreq != bFreq && aFreq != publicFreq && bFreq != publicFreq) //check if two nodes talk, using same non-public frequency
{
this.Disconnect(a, b, true);
return false;
}

bool aMembershipFlag = (a.isHome) ? false : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(a).Connection).getMembershipFlag();
bool bMembershipFlag = (b.isHome) ? false : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(b).Connection).getMembershipFlag();
bool aMembershipFlag, bMembershipFlag;

try
{
aMembershipFlag = (a.isHome) ? false : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(a).Connection).getMembershipFlag();
bMembershipFlag = (b.isHome) ? false : ((CNCCommNetVessel)CNCCommNetScenario.Instance.findCorrespondingVessel(b).Connection).getMembershipFlag();
}
catch(NullReferenceException e) // either CommNode could be a kerbal on EVA
{
this.Disconnect(a, b, true);
return false;
}

if ((aMembershipFlag && aFreq != bFreq && aFreq != publicFreq) ||
(bMembershipFlag && aFreq != bFreq && bFreq != publicFreq)) // check if either node has membership flag to talk to members only
Expand Down

0 comments on commit 78af4b1

Please sign in to comment.