Merge branch 'master' into PrettyLinesDev2
Merge branch 'master' into PrettyLinesDev2

--- a/ARFlightController.cs
+++ b/ARFlightController.cs
@@ -44,6 +44,8 @@
 		#region Fields
 		protected Dictionary<ConnectionStatus, string> connectionTextures;
 
+		protected ARMapRenderer mapRenderer;
+
 		protected IButton toolbarButton;
 		#endregion
 
@@ -128,8 +130,15 @@
 			GameEvents.onVesselChange.Add(this.onVesselChange);
 		}
 
+		protected void Start()
+		{
+			this.mapRenderer = MapView.MapCamera.gameObject.AddComponent<ARMapRenderer>();
+		}
+
 		protected void FixedUpdate()
 		{
+			Tools.DebugLogger log = Tools.DebugLogger.New(this);
+
 			// If we are requiring a connection for control, the vessel does not have any adequately staffed pods,
 			// and the vessel does not have any connected relays...
 			if (
@@ -154,22 +163,41 @@
 				InputLockManager.RemoveControlLock(this.lockID);
 			}
 
-			if (this.toolbarButton != null && HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null)
-			{
+			if (HighLogic.LoadedSceneIsFlight && this.toolbarButton != null && FlightGlobals.ActiveVessel != null)
+			{
+				log.Append("Checking vessel relay status.\n");
+
 				List<ModuleLimitedDataTransmitter> relays =
 					FlightGlobals.ActiveVessel.getModulesOfType<ModuleLimitedDataTransmitter>();
 
+				log.AppendFormat("\t...found {0} relays\n", relays.Count);
+
 				bool vesselCanTransmit = false;
 				bool vesselHasOptimalRelay = false;
 
 				foreach (ModuleLimitedDataTransmitter relay in relays)
 				{
-					if (!vesselCanTransmit && relay.CanTransmit())
+					log.AppendFormat("\tvesselCanTransmit: {0}, vesselHasOptimalRelay: {1}\n",
+						vesselCanTransmit, vesselHasOptimalRelay);
+
+					log.AppendFormat("\tChecking relay {0}\n" +
+						"\t\tCanTransmit: {1}, transmitDistance: {2}, nominalRange: {3}\n",
+						relay,
+						relay.CanTransmit(),
+						relay.transmitDistance,
+						relay.nominalRange
+					);
+
+					bool relayCanTransmit = relay.CanTransmit();
+
+					if (!vesselCanTransmit && relayCanTransmit)
 					{
 						vesselCanTransmit = true;
 					}
 
-					if (!vesselHasOptimalRelay && relay.transmitDistance <= (double)relay.nominalRange)
+					if (!vesselHasOptimalRelay &&
+						relayCanTransmit &&
+						relay.transmitDistance <= (double)relay.nominalRange)
 					{
 						vesselHasOptimalRelay = true;
 					}
@@ -180,6 +208,9 @@
 					}
 				}
 
+				log.AppendFormat("Done checking.  vesselCanTransmit: {0}, vesselHasOptimalRelay: {1}\n",
+					vesselCanTransmit, vesselHasOptimalRelay);
+
 				if (vesselHasOptimalRelay)
 				{
 					this.currentConnectionStatus = ConnectionStatus.Optimal;
@@ -193,8 +224,13 @@
 					this.currentConnectionStatus = ConnectionStatus.None;
 				}
 
+				log.AppendFormat("currentConnectionStatus: {0}, setting texture to {1}",
+					this.currentConnectionStatus, this.currentConnectionTexture);
+
 				this.toolbarButton.TexturePath = this.currentConnectionTexture;
 			}
+
+			log.Print();
 		}
 
 		protected void Destroy()
@@ -204,6 +240,11 @@
 			if (this.toolbarButton != null)
 			{
 				this.toolbarButton.Destroy();
+			}
+
+			if (this.mapRenderer != null)
+			{
+				GameObject.Destroy(this.mapRenderer);
 			}
 
 			GameEvents.onGameSceneLoadRequested.Remove(this.onSceneChangeRequested);
@@ -216,7 +257,7 @@
 		{
 			if (scene != GameScenes.FLIGHT)
 			{
-				MonoBehaviour.Destroy(this);
+				MonoBehaviour.DestroyImmediate(this, true);
 			}
 		}
 

file:b/toolbarIcon.xcf (new)
 Binary files /dev/null and b/toolbarIcon.xcf differ