MapRenderer: Only cleanup if there's something to clean.
MapRenderer: Only cleanup if there's something to clean.

--- a/ARMapRenderer.cs
+++ b/ARMapRenderer.cs
@@ -81,6 +81,8 @@
 		{
 			if (!HighLogic.LoadedSceneIsFlight || !MapView.MapIsEnabled)
 			{
+				this.Cleanup();
+
 				return;
 			}
 
@@ -173,8 +175,8 @@
 
 		private void OnDestroy()
 		{
-			this.vesselLineRenderers.Clear();
-			this.vesselLineRenderers = null;
+			this.Cleanup();
+
 			print("ARMapRenderer: Destroyed.");
 		}
 		#endregion
@@ -247,6 +249,24 @@
 			}
 			while (relay != null);
 		}
+
+		public void Cleanup()
+		{
+			if (this.vesselLineRenderers != null && this.vesselLineRenderers.Count > 0)
+			{
+				foreach (LineRenderer lineRenderer in this.vesselLineRenderers.Values)
+				{
+					lineRenderer.enabled = false;
+					GameObject.Destroy(lineRenderer.gameObject);
+				}
+				this.vesselLineRenderers.Clear();
+			}
+
+			if (this.vesselFrameCache != null && this.vesselFrameCache.Count > 0)
+			{
+				this.vesselFrameCache.Clear();
+			}
+		}
 	}
 }
 

--- a/AntennaRelay.cs
+++ b/AntennaRelay.cs
@@ -38,8 +38,6 @@
 		// We don't have a Bard, so we'll hide Kerbin here.
 		public static CelestialBody Kerbin;
 
-		protected CelestialBody _firstOccludingBody;
-
 		protected IAntennaRelay _nearestRelayCache;
 		protected IAntennaRelay moduleRef;
 
@@ -82,15 +80,12 @@
 		}
 
 		/// <summary>
-		/// Gets the first occluding body.
-		/// </summary>
-		/// <value>The first occluding body.</value>
-		public CelestialBody firstOccludingBody
-		{
-			get
-			{
-				return this._firstOccludingBody;
-			}
+		/// Gets the first <see cref="CelestialBody"/> found to be blocking line of sight.
+		/// </summary>
+		public virtual CelestialBody firstOccludingBody
+		{
+			get;
+			protected set;
 		}
 
 		/// <summary>
@@ -150,19 +145,23 @@
 		/// <returns><c>true</c> if this instance can transmit; otherwise, <c>false</c>.</returns>
 		public virtual bool CanTransmit()
 		{
+			CelestialBody fob = null;
+
 			if (
 				this.transmitDistance > this.maxTransmitDistance ||
 				(
 					ARConfiguration.RequireLineOfSight &&
 					this.nearestRelay == null &&
-					!this.vessel.hasLineOfSightTo(Kerbin, out this._firstOccludingBody)
+					!this.vessel.hasLineOfSightTo(Kerbin, out fob)
 				)
 			)
 			{
+				this.firstOccludingBody = fob;
 				return false;
 			}
 			else
 			{
+				this.firstOccludingBody = null;
 				return true;
 			}
 		}
@@ -193,7 +192,7 @@
 				this.vessel.id
 			));
 
-			this._firstOccludingBody = null;
+			this.firstOccludingBody = null;
 
 			// Set this vessel as checked, so that we don't check it again.
 			RelayDatabase.Instance.CheckedVesselsTable[vessel.id] = true;
@@ -235,9 +234,12 @@
 				}
 
 				// Skip vessels to which we do not have line of sight.
+				CelestialBody fob = null;
+
 				if (ARConfiguration.RequireLineOfSight &&
-					!this.vessel.hasLineOfSightTo(potentialVessel, out this._firstOccludingBody, ARConfiguration.RadiusRatio))
-				{
+					!this.vessel.hasLineOfSightTo(potentialVessel, out fob, ARConfiguration.RadiusRatio))
+				{
+					this.firstOccludingBody = fob;
 					Tools.PostDebugMessage(
 						this,
 						"Vessel {0} discarded because we do not have line of sight.",
@@ -245,6 +247,8 @@
 					);
 					continue;
 				}
+
+				this.firstOccludingBody = null;
 
 				// Find the distance from here to the vessel...
 				double potentialSqrDistance = (potentialVessel.GetWorldPos3D() - vessel.GetWorldPos3D()).sqrMagnitude;

--- a/IAntennaRelay.cs
+++ b/IAntennaRelay.cs
@@ -59,6 +59,12 @@
 		float maxTransmitDistance { get; }
 
 		/// <summary>
+		/// The first CelestialBody blocking line of sight to a 
+		/// </summary>
+		/// <value>The first occluding body.</value>
+		CelestialBody firstOccludingBody { get; }
+
+		/// <summary>
 		/// Gets a value indicating whether this <see cref="AntennaRange.ProtoDataTransmitter"/> has been checked during
 		/// the current relay attempt.
 		/// </summary>

--- a/ModuleLimitedDataTransmitter.cs
+++ b/ModuleLimitedDataTransmitter.cs
@@ -158,6 +158,14 @@
 			get
 			{
 				return Mathf.Sqrt (this.maxPowerFactor) * this.nominalRange;
+			}
+		}
+
+		public CelestialBody firstOccludingBody
+		{
+			get
+			{
+				return this.relay.firstOccludingBody;
 			}
 		}