ARMapRenderer: Fixed up some exceptional cases and generally made it mostly work sometimes for a while.
[AntennaRange.git] / ARMapRenderer.cs
blob:a/ARMapRenderer.cs -> blob:b/ARMapRenderer.cs
--- 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
@@ -221,7 +223,7 @@
 
 					if (MapView.Draw3DLines)
 					{
-						lineWidth = 0.002f * MapView.MapCamera.Distance;
+						lineWidth = 0.004f * MapView.MapCamera.Distance;
 					}
 					else
 					{
@@ -233,8 +235,6 @@
 						float d = Screen.height / 2f + 0.01f;
 						start.z = start.z >= 0f ? d : -d;
 						end.z = end.z >= 0f ? d : -d;
-
-						Debug.Log(string.Format("start.z: {0}", start.z));
 					}
 
 					renderer.SetWidth(lineWidth, lineWidth);
@@ -249,6 +249,17 @@
 			}
 			while (relay != null);
 		}
+
+		public void Cleanup()
+		{
+			foreach (LineRenderer lineRenderer in this.vesselLineRenderers.Values)
+			{
+				lineRenderer.enabled = false;
+				GameObject.Destroy(lineRenderer.gameObject);
+			}
+			this.vesselLineRenderers.Clear();
+			this.vesselFrameCache.Clear();
+		}
 	}
 }