Increased Orbital Period precision + fixes various NullRefs.
Increased Orbital Period precision + fixes various NullRefs.

--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -60,7 +60,6 @@
         private GUIStyle areaStyle;

         private GUIStyle buttonStyle;

         private GUIStyle infoStyle;

-        private GUIStyle settingStyle;

         private GUIStyle titleStyle;

         private GUIStyle windowStyle;

 

@@ -95,7 +94,11 @@
         public bool CompactMode

         {

             get { return this.compactMode; }

-            set { this.compactMode = value; }

+            set

+            {

+                this.compactMode = value; 

+                Logger.Log("BuildAdvanced->CompactMode = " + value);

+            }

         }

 

         /// <summary>

@@ -104,7 +107,11 @@
         public bool ShowAllStages

         {

             get { return this.showAllStages; }

-            set { this.showAllStages = value; }

+            set

+            {

+                this.showAllStages = value; 

+                Logger.Log("BuildAdvanced->ShowAllStages = " + value);

+            }

         }

 

         /// <summary>

@@ -113,7 +120,11 @@
         public bool ShowAtmosphericDetails

         {

             get { return this.showAtmosphericDetails; }

-            set { this.showAtmosphericDetails = value; }

+            set

+            {

+                this.showAtmosphericDetails = value; 

+                Logger.Log("BuildAdvanced->ShowAtmosphericDetails = " + value);

+            }

         }

 

         /// <summary>

@@ -122,7 +133,11 @@
         public bool ShowReferenceBodies

         {

             get { return this.showReferenceBodies; }

-            set { this.showReferenceBodies = value; }

+            set

+            {

+                this.showReferenceBodies = value; 

+                Logger.Log("BuildAdvanced->ShowReferenceBodies = " + value);

+            }

         }

 

         #endregion

@@ -147,60 +162,55 @@
         /// </summary>

         private void InitialiseStyles()

         {

-            this.areaBodiesStyle = new GUIStyle(HighLogic.Skin.box);

-

-            this.windowStyle = new GUIStyle(HighLogic.Skin.window)

-            {

-                alignment = TextAnchor.UpperLeft

-            };

-

-            this.areaStyle = new GUIStyle(HighLogic.Skin.box)

-            {

-                padding = new RectOffset(0, 0, 9, 0)

-            };

-

-            this.buttonStyle = new GUIStyle(HighLogic.Skin.button)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter

-            };

-

-            this.titleStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter,

-                stretchWidth = true

-            };

-

-            this.infoStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter,

-                stretchWidth = true

-            };

-

-            this.settingStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleLeft,

-                stretchWidth = true

-            };

+            try

+            {

+                this.areaBodiesStyle = new GUIStyle(HighLogic.Skin.box);

+

+                this.windowStyle = new GUIStyle(HighLogic.Skin.window)

+                {

+                    alignment = TextAnchor.UpperLeft

+                };

+

+                this.areaStyle = new GUIStyle(HighLogic.Skin.box)

+                {

+                    padding = new RectOffset(0, 0, 9, 0)

+                };

+

+                this.buttonStyle = new GUIStyle(HighLogic.Skin.button)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter

+                };

+

+                this.titleStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter,

+                    stretchWidth = true

+                };

+

+                this.infoStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter,

+                    stretchWidth = true

+                };

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->InitialiseStyles");

+            }

         }

 

         #endregion

@@ -233,8 +243,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildAdvanced->Update");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildAdvanced->Update");

             }

         }

 

@@ -252,26 +261,28 @@
                 // Change the window title based on whether in compact mode or not.

                 var title = !this.compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion;

 

-                // Reset the window size when the staging or something else has changed.

-                var stageCount = SimManager.Stages != null ? SimManager.Stages.Count(stage => this.showAllStages || stage.deltaV > 0) : 0;

-                if (this.hasChanged || stageCount != this.numberOfStages)

-                {

-                    this.hasChanged = false;

-                    this.numberOfStages = stageCount;

-

-                    this.windowPosition.width = 0;

-                    this.windowPosition.height = 0;

-                }

-

-                this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, title, this.windowStyle).ClampToScreen();

-

-                // Check editor lock to manage click-through.

-                this.CheckEditorLock();

-            }

-            catch (Exception ex)

-            {

-                Logger.Log("BuildAdvanced->OnDraw");

-                Logger.Exception(ex);

+                if (SimManager.Stages != null)

+                {

+                    // Reset the window size when the staging or something else has changed.

+                    var stageCount = SimManager.Stages.Count(stage => this.showAllStages || stage.deltaV > 0);

+                    if (this.hasChanged || stageCount != this.numberOfStages)

+                    {

+                        this.hasChanged = false;

+                        this.numberOfStages = stageCount;

+

+                        this.windowPosition.width = 0;

+                        this.windowPosition.height = 0;

+                    }

+

+                    this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, title, this.windowStyle).ClampToScreen();

+

+                    // Check editor lock to manage click-through.

+                    this.CheckEditorLock();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->OnDraw");

             }

         }

 

@@ -280,15 +291,22 @@
         /// </summary>

         private void CheckEditorLock()

         {

-            if (this.windowPosition.MouseIsOver())

-            {

-                EditorLogic.fetch.State = EditorLogic.EditorState.GUI_SELECTED;

-                this.isEditorLocked = true;

-            }

-            else if (!this.windowPosition.MouseIsOver() && this.isEditorLocked)

-            {

-                EditorLogic.fetch.State = EditorLogic.EditorState.PAD_UNSELECTED;

-                this.isEditorLocked = false;

+            try

+            {

+                if (this.windowPosition.MouseIsOver())

+                {

+                    EditorLogic.fetch.State = EditorLogic.EditorState.GUI_SELECTED;

+                    this.isEditorLocked = true;

+                }

+                else if (!this.windowPosition.MouseIsOver() && this.isEditorLocked)

+                {

+                    EditorLogic.fetch.State = EditorLogic.EditorState.PAD_UNSELECTED;

+                    this.isEditorLocked = false;

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->CheckEditorLock");

             }

         }

 

@@ -297,94 +315,108 @@
         /// </summary>

         private void Window(int windowId)

         {

-            // Draw the compact mode toggle.

-            if (GUI.Toggle(new Rect(this.windowPosition.width - 70.0f, 5.0f, 65.0f, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode)

-            {

-                this.hasChanged = true;

-                this.compactMode = !this.compactMode;

-            }

-

-            // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.

-            if (!this.compactMode)

-            {

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 153.0f, 5.0f, 80.0f, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages)

+            try

+            {

+                // Draw the compact mode toggle.

+                if (GUI.Toggle(new Rect(this.windowPosition.width - 70.0f, 5.0f, 65.0f, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode)

                 {

                     this.hasChanged = true;

-                    this.showAllStages = !this.showAllStages;

-                }

-

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 251.0f, 5.0f, 95.0f, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails)

-                {

-                    this.hasChanged = true;

-                    this.showAtmosphericDetails = !this.showAtmosphericDetails;

-                }

-

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 379.0f, 5.0f, 125.0f, 20.0f), this.showReferenceBodies, "REFERENCE BODIES", this.buttonStyle) != this.showReferenceBodies)

-                {

-                    this.hasChanged = true;

-                    this.showReferenceBodies = !this.showReferenceBodies;

-                }

-            }

-

-            // Draw the main informational display box.

-

-            if (!this.compactMode)

-            {

-                GUILayout.BeginHorizontal(this.areaStyle);

-                this.DrawStageNumbers();

-                //this.DrawPartCount();

-                this.DrawCost();

-                this.DrawMass();

-                this.DrawIsp();

-                this.DrawThrust();

-                this.DrawTwr();

-                this.DrawDeltaV();

-                this.DrawBurnTime();

+                    this.compactMode = !this.compactMode;

+                }

+

+                // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.

+                if (!this.compactMode)

+                {

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 153.0f, 5.0f, 80.0f, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages)

+                    {

+                        this.hasChanged = true;

+                        this.showAllStages = !this.showAllStages;

+                    }

+

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 251.0f, 5.0f, 95.0f, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails)

+                    {

+                        this.hasChanged = true;

+                        this.showAtmosphericDetails = !this.showAtmosphericDetails;

+                    }

+

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 379.0f, 5.0f, 125.0f, 20.0f), this.showReferenceBodies, "REFERENCE BODIES", this.buttonStyle) != this.showReferenceBodies)

+                    {

+                        this.hasChanged = true;

+                        this.showReferenceBodies = !this.showReferenceBodies;

+                    }

+                }

+

+                // Draw the main informational display box.

+

+                if (!this.compactMode)

+                {

+                    GUILayout.BeginHorizontal(this.areaStyle);

+                    this.DrawStageNumbers();

+                    //this.DrawPartCount();

+                    this.DrawCost();

+                    this.DrawMass();

+                    this.DrawIsp();

+                    this.DrawThrust();

+                    this.DrawTwr();

+                    this.DrawDeltaV();

+                    this.DrawBurnTime();

+                    GUILayout.EndHorizontal();

+

+                    if (this.showAtmosphericDetails)

+                    {

+                        GUILayout.BeginVertical(this.areaStyle);

+                        this.DrawAtmosphericDetails();

+                        GUILayout.EndVertical();

+                    }

+

+                    if (this.showReferenceBodies)

+                    {

+                        GUILayout.BeginVertical(this.areaBodiesStyle);

+                        this.DrawReferenceBodies();

+                        GUILayout.EndVertical();

+                    }

+                }

+                else // Draw only a few details when in compact mode.

+                {

+                    GUILayout.BeginHorizontal(this.areaStyle);

+                    this.DrawStageNumbers();

+                    this.DrawTwr();

+                    this.DrawDeltaV();

+                    GUILayout.EndHorizontal();

+                }

+

+                GUI.DragWindow();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->Window");

+            }

+        }

+

+        /// <summary>

+        ///     Draws the atmospheric settings.

+        /// </summary>

+        private void DrawAtmosphericDetails()

+        {

+            try

+            {

+                GUILayout.BeginHorizontal();

+                GUILayout.Label("Pressure " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.titleStyle, GUILayout.Width(125.0f));

+                GUI.skin = HighLogic.Skin;

+                this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);

+                GUI.skin = null;

                 GUILayout.EndHorizontal();

-

-                if (this.showAtmosphericDetails)

-                {

-                    GUILayout.BeginVertical(this.areaStyle);

-                    this.DrawAtmosphericDetails();

-                    GUILayout.EndVertical();

-                }

-

-                if (this.showReferenceBodies)

-                {

-                    GUILayout.BeginVertical(this.areaBodiesStyle);

-                    this.DrawReferenceBodies();

-                    GUILayout.EndVertical();

-                }

-            }

-            else // Draw only a few details when in compact mode.

-            {

-                GUILayout.BeginHorizontal(this.areaStyle);

-                this.DrawStageNumbers();

-                this.DrawTwr();

-                this.DrawDeltaV();

+                GUILayout.BeginHorizontal();

+                GUILayout.Label("Velocity " + this.atmosphericVelocity.ToString("F1") + "m/s", this.titleStyle, GUILayout.Width(125.0f));

+                GUI.skin = HighLogic.Skin;

+                this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f);

+                GUI.skin = null;

                 GUILayout.EndHorizontal();

             }

-

-            GUI.DragWindow();

-        }

-

-        /// <summary>

-        ///     Draws the atmospheric settings.

-        /// </summary>

-        private void DrawAtmosphericDetails()

-        {

-            GUILayout.BeginHorizontal();

-            GUILayout.Label("Pressure " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.titleStyle, GUILayout.Width(125.0f));

-            GUI.skin = HighLogic.Skin;

-            this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);

-            GUI.skin = null;

-            GUILayout.EndHorizontal();

-            GUILayout.BeginHorizontal();

-            GUILayout.Label("Velocity " + this.atmosphericVelocity.ToString("F1") + "m/s", this.titleStyle, GUILayout.Width(125.0f));

-            GUI.skin = HighLogic.Skin;

-            this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f);

-            GUI.skin = null;

-            GUILayout.EndHorizontal();

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawAtmosphericDetails");

+            }

         }

 

         /// <summary>

@@ -392,25 +424,32 @@
         /// </summary>

         private void DrawReferenceBodies()

         {

-            var index = 0;

-

-            foreach (var bodyName in CelestialBodies.Instance.BodyList.Keys)

-            {

-                if (index % 8 == 0)

-                {

-                    if (index > 0)

-                    {

-                        GUILayout.EndHorizontal();

-                    }

-                    GUILayout.BeginHorizontal();

-                }

-                if (GUILayout.Toggle(CelestialBodies.Instance.SelectedBodyName == bodyName, bodyName, this.buttonStyle))

-                {

-                    CelestialBodies.Instance.SelectedBodyName = bodyName;

-                }

-                index++;

-            }

-            GUILayout.EndHorizontal();

+            try

+            {

+                var index = 0;

+

+                foreach (var bodyName in CelestialBodies.Instance.BodyList.Keys)

+                {

+                    if (index % 8 == 0)

+                    {

+                        if (index > 0)

+                        {

+                            GUILayout.EndHorizontal();

+                        }

+                        GUILayout.BeginHorizontal();

+                    }

+                    if (GUILayout.Toggle(CelestialBodies.Instance.SelectedBodyName == bodyName, bodyName, this.buttonStyle))

+                    {

+                        CelestialBodies.Instance.SelectedBodyName = bodyName;

+                    }

+                    index++;

+                }

+                GUILayout.EndHorizontal();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawReferenceBodies");

+            }

         }

 

         /// <summary>

@@ -418,16 +457,23 @@
         /// </summary>

         private void DrawStageNumbers()

         {

-            GUILayout.BeginVertical(GUILayout.Width(30.0f));

-            GUILayout.Label(string.Empty, this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label("S" + stage.number, this.titleStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(30.0f));

+                GUILayout.Label(string.Empty, this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label("S" + stage.number, this.titleStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawStageNumbers");

+            }

         }

 

         /// <summary>

@@ -435,16 +481,24 @@
         /// </summary>

         private void DrawPartCount()

         {

-            GUILayout.BeginVertical(GUILayout.Width(50.0f));

-            GUILayout.Label("PARTS", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    //GUILayout.Label(stage.PartCount.ToString("N0"), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+

+                GUILayout.BeginVertical(GUILayout.Width(50.0f));

+                GUILayout.Label("PARTS", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        //GUILayout.Label(stage.PartCount.ToString("N0"), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawPartCount");

+            }

         }

 

         /// <summary>

@@ -452,16 +506,23 @@
         /// </summary>

         private void DrawCost()

         {

-            GUILayout.BeginVertical(GUILayout.Width(110.0f));

-            GUILayout.Label("COST", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(110.0f));

+                GUILayout.Label("COST", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawCost");

+            }

         }

 

         /// <summary>

@@ -469,16 +530,24 @@
         /// </summary>

         private void DrawMass()

         {

-            GUILayout.BeginVertical(GUILayout.Width(110.0f));

-            GUILayout.Label("MASS", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.mass.ToMass(false) + " / " + stage.totalMass.ToMass(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+

+                GUILayout.BeginVertical(GUILayout.Width(110.0f));

+                GUILayout.Label("MASS", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.mass.ToMass(false) + " / " + stage.totalMass.ToMass(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawMass");

+            }

         }

 

         /// <summary>

@@ -486,16 +555,23 @@
         /// </summary>

         private void DrawIsp()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("ISP", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("ISP", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawIsp");

+            }

         }

 

         /// <summary>

@@ -503,16 +579,23 @@
         /// </summary>

         private void DrawThrust()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("THRUST", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("THRUST", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawThrust");

+            }

         }

 

         /// <summary>

@@ -520,16 +603,23 @@
         /// </summary>

         private void DrawTwr()

         {

-            GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            GUILayout.Label("TWR (MAX)", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(100.0f));

+                GUILayout.Label("TWR (MAX)", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawTwr");

+            }

         }

 

         /// <summary>

@@ -537,16 +627,23 @@
         /// </summary>

         private void DrawDeltaV()

         {

-            GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            GUILayout.Label("DELTA-V", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(100.0f));

+                GUILayout.Label("DELTA-V", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawDeltaV");

+            }

         }

 

         /// <summary>

@@ -554,16 +651,23 @@
         /// </summary>

         private void DrawBurnTime()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("BURN", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.time.ToTime(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("BURN", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.time.ToTime(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawBurnTime");

+            }

         }

 

         #endregion

@@ -590,8 +694,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildAdvanced->OnDestroy");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildAdvanced->OnDestroy");

             }

         }

 

@@ -613,8 +716,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildAdvanced->Load");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildAdvanced->Load");

             }

         }

 


--- a/KerbalEngineer/Editor/BuildOverlay.cs
+++ b/KerbalEngineer/Editor/BuildOverlay.cs
@@ -79,7 +79,11 @@
         public float TooltipInfoDelay

         {

             get { return this.tooltipInfoDelay; }

-            set { this.tooltipInfoDelay = value; }

+            set

+            {

+                this.tooltipInfoDelay = value;

+                Logger.Log("BuildOverlay->TooltipInfoDelay = " + value);

+            }

         }

 

         /// <summary>

@@ -107,51 +111,58 @@
 

         private void InitialiseStyles()

         {

-            this.windowStyle = new GUIStyle(GUIStyle.none)

-            {

-                margin = new RectOffset(),

-                padding = new RectOffset()

-            };

-

-            this.titleStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                margin = new RectOffset(),

-                padding = new RectOffset(),

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                stretchWidth = true

-            };

-

-            this.infoStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                margin = new RectOffset(),

-                padding = new RectOffset(),

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                stretchWidth = true

-            };

-

-            this.tooltipTitleStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                stretchWidth = true

-            };

-

-            this.tooltipInfoStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                stretchWidth = true

-            };

+            try

+            {

+                this.windowStyle = new GUIStyle(GUIStyle.none)

+                {

+                    margin = new RectOffset(),

+                    padding = new RectOffset()

+                };

+

+                this.titleStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    margin = new RectOffset(),

+                    padding = new RectOffset(),

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    stretchWidth = true

+                };

+

+                this.infoStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    margin = new RectOffset(),

+                    padding = new RectOffset(),

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    stretchWidth = true

+                };

+

+                this.tooltipTitleStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    stretchWidth = true

+                };

+

+                this.tooltipInfoStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    stretchWidth = true

+                };

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildOverlay->InitialiseStyles");

+            }

         }

 

         #endregion

@@ -183,8 +194,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildOverlay->Update");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildOverlay->Update");

             }

         }

 

@@ -192,7 +202,7 @@
         {

             try

             {

-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)

+                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts || SimManager.LastStage == null)

                 {

                     return;

                 }

@@ -250,30 +260,36 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildOverlay->OnDraw");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildOverlay->OnDraw");

             }

         }

 

         private void Window(int windowId)

         {

-            GUILayout.BeginHorizontal();

-

-            // Titles

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            //GUILayout.Label("Parts:", this.titleStyle);

-            GUILayout.Label("Delta-V:", this.titleStyle);

-            GUILayout.Label("TWR:", this.titleStyle);

-            GUILayout.EndVertical();

-

-            // Details

-            GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            //GUILayout.Label(SimulationManager.Instance.LastStage.partCount.ToString("N0"), this.infoStyle);

-            GUILayout.Label(SimManager.LastStage.totalDeltaV.ToString("N0") + " m/s", this.infoStyle);

-            GUILayout.Label(SimManager.LastStage.thrustToWeight.ToString("F2"), this.infoStyle);

-            GUILayout.EndVertical();

-

-            GUILayout.EndHorizontal();

+            try

+            {

+                GUILayout.BeginHorizontal();

+

+                // Titles

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                //GUILayout.Label("Parts:", this.titleStyle);

+                GUILayout.Label("Delta-V:", this.titleStyle);

+                GUILayout.Label("TWR:", this.titleStyle);

+                GUILayout.EndVertical();

+

+                // Details

+                GUILayout.BeginVertical(GUILayout.Width(100.0f));

+                //GUILayout.Label(SimulationManager.Instance.LastStage.partCount.ToString("N0"), this.infoStyle);

+                GUILayout.Label(SimManager.LastStage.totalDeltaV.ToString("N0") + " m/s", this.infoStyle);

+                GUILayout.Label(SimManager.LastStage.thrustToWeight.ToString("F2"), this.infoStyle);

+                GUILayout.EndVertical();

+

+                GUILayout.EndHorizontal();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildOverlay->Window");

+            }

         }

 

         /// <summary>

@@ -281,143 +297,157 @@
         /// </summary>

         private void DrawTooltip(Part part)

         {

-            // Tooltip title (name of part).

-            var content = new GUIContent(part.partInfo.title);

-            var size = this.tooltipTitleStyle.CalcSize(content);

-            var position = new Rect(Event.current.mousePosition.x + 16.0f, Event.current.mousePosition.y, size.x, size.y).ClampInsideScreen();

-

-            if (position.x < Event.current.mousePosition.x + 16.0f)

-            {

+            try

+            {

+                // Tooltip title (name of part).

+                var content = new GUIContent(part.partInfo.title);

+                var size = this.tooltipTitleStyle.CalcSize(content);

+                var position = new Rect(Event.current.mousePosition.x + 16.0f, Event.current.mousePosition.y, size.x, size.y).ClampInsideScreen();

+

+                if (position.x < Event.current.mousePosition.x + 16.0f)

+                {

+                    position.y += 16.0f;

+                }

+                GUI.Label(position, content, this.tooltipTitleStyle);

+

+                // After hovering for a period of time, show extended information.

+                if (this.tooltipInfoTimer.Elapsed.TotalSeconds >= this.tooltipInfoDelay)

+                {

+                    // Stop the timer as it is no longer needed.

+                    if (this.tooltipInfoTimer.IsRunning)

+                    {

+                        this.tooltipInfoTimer.Stop();

+                    }

+

+                    // Show the dry mass of the part if applicable.

+                    if (part.physicalSignificance == Part.PhysicalSignificance.FULL)

+                    {

+                        this.DrawTooltipInfo(ref position, "Dry Mass: " + part.GetDryMass().ToMass());

+                    }

+

+                    // Show resources contained within the part.

+                    if (part.ContainsResources())

+                    {

+                        // Show the wet mass of the part if applicable.

+                        if (part.GetResourceMass() > 0)

+                        {

+                            this.DrawTooltipInfo(ref position, "Wet Mass: " + part.GetWetMass().ToMass());

+                        }

+

+                        // List all the resources contained within the part.

+                        foreach (PartResource resource in part.Resources)

+                        {

+                            if (resource.GetDensity() > 0)

+                            {

+                                this.DrawTooltipInfo(ref position, resource.info.name + ": " + resource.GetMass().ToMass() + " (" + resource.amount + ")");

+                            }

+                            else

+                            {

+                                this.DrawTooltipInfo(ref position, resource.info.name + ": " + resource.amount);

+                            }

+                        }

+                    }

+

+                    // Show details for engines.

+                    if (part.IsEngine())

+                    {

+                        this.DrawTooltipInfo(ref position, "Maximum Thrust: " + part.GetMaxThrust().ToForce());

+                        this.DrawTooltipInfo(ref position, "Specific Impulse: " + part.GetSpecificImpulse(1f) + " / " + part.GetSpecificImpulse(0f) + "s");

+

+                        // Thrust vectoring.

+                        if (part.HasModule("ModuleGimbal"))

+                        {

+                            this.DrawTooltipInfo(ref position, "Thrust Vectoring Enabled");

+                        }

+

+                        // Contains alternator.

+                        if (part.HasModule("ModuleAlternator"))

+                        {

+                            this.DrawTooltipInfo(ref position, "Contains Alternator");

+                        }

+                    }

+

+                    // Show details for RCS.

+                    if (part.IsRcsModule())

+                    {

+                        var moduleRcs = part.GetModuleRcs();

+                        this.DrawTooltipInfo(ref position, "Thrust Power: " + moduleRcs.thrusterPower.ToDouble().ToForce());

+                        this.DrawTooltipInfo(ref position, "Specific Impulse: " + moduleRcs.atmosphereCurve.Evaluate(1f) + " / " + moduleRcs.atmosphereCurve.Evaluate(0f) + "s");

+                    }

+

+                    // Show details for solar panels.

+                    if (part.IsSolarPanel())

+                    {

+                        this.DrawTooltipInfo(ref position, "Charge Rate: " + part.GetModuleDeployableSolarPanel().chargeRate.ToDouble().ToRate());

+                    }

+

+                    // Show details for generators.

+                    if (part.IsGenerator())

+                    {

+                        foreach (var resource in part.GetModuleGenerator().inputList)

+                        {

+                            this.DrawTooltipInfo(ref position, "Input: " + resource.name + " (" + resource.rate.ToDouble().ToRate() + ")");

+                        }

+

+                        foreach (var resource in part.GetModuleGenerator().outputList)

+                        {

+                            this.DrawTooltipInfo(ref position, "Output: " + resource.name + " (" + resource.rate.ToDouble().ToRate() + ")");

+                        }

+                    }

+

+                    // Show details for parachutes.

+                    if (part.IsParachute())

+                    {

+                        var module = part.GetModuleParachute();

+                        this.DrawTooltipInfo(ref position, "Semi Deployed Drag: " + module.semiDeployedDrag);

+                        this.DrawTooltipInfo(ref position, "Fully Deployed Drag: " + module.fullyDeployedDrag);

+                        this.DrawTooltipInfo(ref position, "Deployment Altitude: " + module.deployAltitude.ToDouble().ToDistance());

+                    }

+

+                    // Contains stability augmentation system.

+                    if (part.HasModule("ModuleSAS"))

+                    {

+                        this.DrawTooltipInfo(ref position, "Contains SAS");

+                    }

+

+                    // Contains reaction wheels.

+                    if (part.HasModule("ModuleReactionWheel"))

+                    {

+                        this.DrawTooltipInfo(ref position, "Contains Reaction Wheels");

+                    }

+

+                    // Show if the part has an animation that can only be used once.

+                    if (part.HasOneShotAnimation())

+                    {

+                        this.DrawTooltipInfo(ref position, "Single Activation Only");

+                    }

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildOverlay->DrawTooltip");

+            }

+        }

+

+        /// <summary>

+        ///     Draws a line of extended information below the previous.

+        /// </summary>

+        private void DrawTooltipInfo(ref Rect position, string value)

+        {

+            try

+            {

+                var content = new GUIContent(value);

+                var size = this.tooltipInfoStyle.CalcSize(content);

+

                 position.y += 16.0f;

-            }

-            GUI.Label(position, content, this.tooltipTitleStyle);

-

-            // After hovering for a period of time, show extended information.

-            if (this.tooltipInfoTimer.Elapsed.TotalSeconds >= this.tooltipInfoDelay)

-            {

-                // Stop the timer as it is no longer needed.

-                if (this.tooltipInfoTimer.IsRunning)

-                {

-                    this.tooltipInfoTimer.Stop();

-                }

-

-                // Show the dry mass of the part if applicable.

-                if (part.physicalSignificance == Part.PhysicalSignificance.FULL)

-                {

-                    this.DrawTooltipInfo(ref position, "Dry Mass: " + part.GetDryMass().ToMass());

-                }

-

-                // Show resources contained within the part.

-                if (part.ContainsResources())

-                {

-                    // Show the wet mass of the part if applicable.

-                    if (part.GetResourceMass() > 0)

-                    {

-                        this.DrawTooltipInfo(ref position, "Wet Mass: " + part.GetWetMass().ToMass());

-                    }

-

-                    // List all the resources contained within the part.

-                    foreach (PartResource resource in part.Resources)

-                    {

-                        if (resource.GetDensity() > 0)

-                        {

-                            this.DrawTooltipInfo(ref position, resource.info.name + ": " + resource.GetMass().ToMass() + " (" + resource.amount + ")");

-                        }

-                        else

-                        {

-                            this.DrawTooltipInfo(ref position, resource.info.name + ": " + resource.amount);

-                        }

-                    }

-                }

-

-                // Show details for engines.

-                if (part.IsEngine())

-                {

-                    this.DrawTooltipInfo(ref position, "Maximum Thrust: " + part.GetMaxThrust().ToForce());

-                    this.DrawTooltipInfo(ref position, "Specific Impulse: " + part.GetSpecificImpulse(1f) + " / " + part.GetSpecificImpulse(0f) + "s");

-

-                    // Thrust vectoring.

-                    if (part.HasModule("ModuleGimbal"))

-                    {

-                        this.DrawTooltipInfo(ref position, "Thrust Vectoring Enabled");

-                    }

-

-                    // Contains alternator.

-                    if (part.HasModule("ModuleAlternator"))

-                    {

-                        this.DrawTooltipInfo(ref position, "Contains Alternator");

-                    }

-                }

-

-                // Show details for RCS.

-                if (part.IsRcsModule())

-                {

-                    var moduleRcs = part.GetModuleRcs();

-                    this.DrawTooltipInfo(ref position, "Thrust Power: " + moduleRcs.thrusterPower.ToDouble().ToForce());

-                    this.DrawTooltipInfo(ref position, "Specific Impulse: " + moduleRcs.atmosphereCurve.Evaluate(1f) + " / " + moduleRcs.atmosphereCurve.Evaluate(0f) + "s");

-                }

-

-                // Show details for solar panels.

-                if (part.IsSolarPanel())

-                {

-                    this.DrawTooltipInfo(ref position, "Charge Rate: " + part.GetModuleDeployableSolarPanel().chargeRate.ToDouble().ToRate());

-                }

-

-                // Show details for generators.

-                if (part.IsGenerator())

-                {

-                    foreach (var resource in part.GetModuleGenerator().inputList)

-                    {

-                        this.DrawTooltipInfo(ref position, "Input: " + resource.name + " (" + resource.rate.ToDouble().ToRate() + ")");

-                    }

-

-                    foreach (var resource in part.GetModuleGenerator().outputList)

-                    {

-                        this.DrawTooltipInfo(ref position, "Output: " + resource.name + " (" + resource.rate.ToDouble().ToRate() + ")");

-                    }

-                }

-

-                // Show details for parachutes.

-                if (part.IsParachute())

-                {

-                    var module = part.GetModuleParachute();

-                    this.DrawTooltipInfo(ref position, "Semi Deployed Drag: " + module.semiDeployedDrag);

-                    this.DrawTooltipInfo(ref position, "Fully Deployed Drag: " + module.fullyDeployedDrag);

-                    this.DrawTooltipInfo(ref position, "Deployment Altitude: " + module.deployAltitude.ToDouble().ToDistance());

-                }

-

-                // Contains stability augmentation system.

-                if (part.HasModule("ModuleSAS"))

-                {

-                    this.DrawTooltipInfo(ref position, "Contains SAS");

-                }

-

-                // Contains reaction wheels.

-                if (part.HasModule("ModuleReactionWheel"))

-                {

-                    this.DrawTooltipInfo(ref position, "Contains Reaction Wheels");

-                }

-

-                // Show if the part has an animation that can only be used once.

-                if (part.HasOneShotAnimation())

-                {

-                    this.DrawTooltipInfo(ref position, "Single Activation Only");

-                }

-            }

-        }

-

-        /// <summary>

-        ///     Draws a line of extended information below the previous.

-        /// </summary>

-        private void DrawTooltipInfo(ref Rect position, string value)

-        {

-            var content = new GUIContent(value);

-            var size = this.tooltipInfoStyle.CalcSize(content);

-

-            position.y += 16.0f;

-            position.width = size.x;

-            position.height = size.y;

-            GUI.Label(position, content, this.tooltipInfoStyle);

+                position.width = size.x;

+                position.height = size.y;

+                GUI.Label(position, content, this.tooltipInfoStyle);

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildOverlay->DrawTooltipInfo");

+            }

         }

 

         #endregion

@@ -437,8 +467,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildOverlay->OnDestroy");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildOverlay->OnDestroy");

             }

         }

 

@@ -454,8 +483,7 @@
             }

             catch (Exception ex)

             {

-                Logger.Log("BuildOverlay->Load");

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildOverlay->Load");

             }

         }

 


--- a/KerbalEngineer/Extensions/DoubleExtensions.cs
+++ b/KerbalEngineer/Extensions/DoubleExtensions.cs
@@ -17,6 +17,12 @@
 //     along with this program.  If not, see <http://www.gnu.org/licenses/>.

 // 

 

+#region Using Directives

+

+using System;

+

+#endregion

+

 namespace KerbalEngineer.Extensions

 {

     public static class DoubleExtensions

@@ -26,7 +32,15 @@
         /// </summary>

         public static float ToFloat(this double value)

         {

-            return (float)value;

+            try

+            {

+                return (float)value;

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToFloat");

+                return 0;

+            }

         }

 

         /// <summary>

@@ -34,7 +48,16 @@
         /// </summary>

         public static string ToMass(this double value, bool showNotation = true)

         {

-            return ToFloat(value).ToMass(showNotation);

+            try

+            {

+                value *= 1000;

+                return showNotation ? value.ToString("N0") + "kg" : value.ToString("N0");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToMass");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -42,7 +65,15 @@
         /// </summary>

         public static string ToForce(this double value, bool showNotation = true)

         {

-            return ToFloat(value).ToForce(showNotation);

+            try

+            {

+                return showNotation ? value.ToString("N2") + "kN" : value.ToString("N2");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToForce");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -50,7 +81,15 @@
         /// </summary>

         public static string ToSpeed(this double value, bool showNotation = true)

         {

-            return ToFloat(value).ToSpeed(showNotation);

+            try

+            {

+                return showNotation ? value.ToString("N2") + "m/s" : value.ToString("N2");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToSpeed");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -58,7 +97,58 @@
         /// </summary>

         public static string ToDistance(this double value)

         {

-            return ToFloat(value).ToDistance();

+            try

+            {

+                var negative = value < 0;

+

+                if (negative)

+                {

+                    value = -value;

+                }

+

+                if (value < 1000000.0f)

+                {

+                    if (value < 1.0f)

+                    {

+                        value *= 1000.0f;

+

+                        if (negative)

+                        {

+                            value = -value;

+                        }

+                        return value.ToString("N0") + "mm";

+                    }

+

+                    if (negative)

+                    {

+                        value = -value;

+                    }

+                    return value.ToString("N0") + "m";

+                }

+

+                value /= 1000.0f;

+                if (value >= 1000000.0f)

+                {

+                    value /= 1000.0f;

+

+                    if (negative)

+                    {

+                        value = -value;

+                    }

+                    return value.ToString("N0") + "Mm";

+                }

+

+                if (negative)

+                {

+                    value = -value;

+                }

+                return value.ToString("N0") + "km";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToDistance");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -66,7 +156,15 @@
         /// </summary>

         public static string ToRate(this double value)

         {

-            return ToFloat(value).ToRate();

+            try

+            {

+                return value > 0 ? value.ToString("F1") + "/sec" : (60.0f * value).ToString("F1") + "/min";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToRate");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -74,15 +172,85 @@
         /// </summary>

         public static string ToAngle(this double value)

         {

-            return ToFloat(value).ToAngle();

+            try

+            {

+                return value.ToString("F3") + "°";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToAngle");

+                return "ERR";

+            }

         }

 

         /// <summary>

         ///     Convert to string formatted as a time.

         /// </summary>

-        public static string ToTime(this double value)

-        {

-            return ToFloat(value).ToTime();

+        public static string ToTime(this double value, string format = "F1")

+        {

+            try

+            {

+                var s = value;

+                var m = 0;

+                var h = 0;

+                var d = 0;

+                var y = 0;

+

+                // Years

+                while (s >= 31536000)

+                {

+                    y++;

+                    s -= 31536000;

+                }

+

+                // Days

+                while (s >= 86400)

+                {

+                    d++;

+                    s -= 86400;

+                }

+

+                // Hours

+                while (s >= 3600)

+                {

+                    h++;

+                    s -= 3600;

+                }

+

+                // Minutes

+                while (s >= 60)

+                {

+                    m++;

+                    s -= 60;

+                }

+

+                if (y > 0)

+                {

+                    return y + "y " + d + "d " + h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (d > 0)

+                {

+                    return d + "d " + h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (h > 0)

+                {

+                    return h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (m > 0)

+                {

+                    return m + "m " + s.ToString(format) + "s";

+                }

+

+                return s.ToString(format) + "s";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "DoubleExtentions->ToTime");

+                return "ERR";

+            }

         }

     }

 }

--- a/KerbalEngineer/Extensions/FloatExtensions.cs
+++ b/KerbalEngineer/Extensions/FloatExtensions.cs
@@ -17,6 +17,8 @@
 //     along with this program.  If not, see <http://www.gnu.org/licenses/>.

 // 

 

+using System;

+

 namespace KerbalEngineer.Extensions

 {

     public static class FloatExtensions

@@ -26,7 +28,15 @@
         /// </summary>

         public static double ToDouble(this float value)

         {

-            return value;

+            try

+            {

+                return value;

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToDouble");

+                return 0;

+            }

         }

 

         /// <summary>

@@ -34,9 +44,16 @@
         /// </summary>

         public static string ToMass(this float value, bool showNotation = true)

         {

-            value *= 1000;

-

-            return showNotation ? value.ToString("N0") + "kg" : value.ToString("N0");

+            try

+            {

+                value *= 1000;

+                return showNotation ? value.ToString("N0") + "kg" : value.ToString("N0");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToMass");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -44,7 +61,15 @@
         /// </summary>

         public static string ToForce(this float value, bool showNotation = true)

         {

-            return showNotation ? value.ToString("N2") + "kN" : value.ToString("N2");

+            try

+            {

+                return showNotation ? value.ToString("N2") + "kN" : value.ToString("N2");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToForce");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -52,7 +77,15 @@
         /// </summary>

         public static string ToSpeed(this float value, bool showNotation = true)

         {

-            return showNotation ? value.ToString("N2") + "m/s" : value.ToString("N2");

+            try

+            {

+                return showNotation ? value.ToString("N2") + "m/s" : value.ToString("N2");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToSpeed");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -60,50 +93,58 @@
         /// </summary>

         public static string ToDistance(this float value)

         {

-            var negative = value < 0;

-

-            if (negative)

-            {

-                value = -value;

-            }

-

-            if (value < 1000000.0f)

-            {

-                if (value < 1.0f)

-                {

-                    value *= 1000.0f;

+            try

+            {

+                var negative = value < 0;

+

+                if (negative)

+                {

+                    value = -value;

+                }

+

+                if (value < 1000000.0f)

+                {

+                    if (value < 1.0f)

+                    {

+                        value *= 1000.0f;

+

+                        if (negative)

+                        {

+                            value = -value;

+                        }

+                        return value.ToString("N0") + "mm";

+                    }

 

                     if (negative)

                     {

                         value = -value;

                     }

-                    return value.ToString("N0") + "mm";

+                    return value.ToString("N0") + "m";

+                }

+

+                value /= 1000.0f;

+                if (value >= 1000000.0f)

+                {

+                    value /= 1000.0f;

+

+                    if (negative)

+                    {

+                        value = -value;

+                    }

+                    return value.ToString("N0") + "Mm";

                 }

 

                 if (negative)

                 {

                     value = -value;

                 }

-                return value.ToString("N0") + "m";

-            }

-

-            value /= 1000.0f;

-            if (value >= 1000000.0f)

-            {

-                value /= 1000.0f;

-

-                if (negative)

-                {

-                    value = -value;

-                }

-                return value.ToString("N0") + "Mm";

-            }

-

-            if (negative)

-            {

-                value = -value;

-            }

-            return value.ToString("N0") + "km";

+                return value.ToString("N0") + "km";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToDistance");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -111,7 +152,15 @@
         /// </summary>

         public static string ToRate(this float value)

         {

-            return value > 0 ? value.ToString("F1") + "/sec" : (60.0f * value).ToString("F1") + "/min";

+            try

+            {

+                return value > 0 ? value.ToString("F1") + "/sec" : (60.0f * value).ToString("F1") + "/min";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToRate");

+                return "ERR";

+            }

         }

 

         /// <summary>

@@ -119,69 +168,85 @@
         /// </summary>

         public static string ToAngle(this float value)

         {

-            return value.ToString("F3") + "°";

+            try

+            {

+                return value.ToString("F3") + "°";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtentions->ToAngle");

+                return "ERR";

+            }

         }

 

         /// <summary>

         ///     Convert to string formatted as a time.

         /// </summary>

-        public static string ToTime(this float value)

-        {

-            var s = value;

-            var m = 0;

-            var h = 0;

-            var d = 0;

-            var y = 0;

-

-            // Years

-            while (s >= 31536000)

-            {

-                y++;

-                s -= 31536000;

-            }

-

-            // Days

-            while (s >= 86400)

-            {

-                d++;

-                s -= 86400;

-            }

-

-            // Hours

-            while (s >= 3600)

-            {

-                h++;

-                s -= 3600;

-            }

-

-            // Minutes

-            while (s >= 60)

-            {

-                m++;

-                s -= 60;

-            }

-

-            if (y > 0)

-            {

-                return y + "y " + d + "d " + h + "h " + m + "m " + s.ToString("F1") + "s";

-            }

-

-            if (d > 0)

-            {

-                return d + "d " + h + "h " + m + "m " + s.ToString("F1") + "s";

-            }

-

-            if (h > 0)

-            {

-                return h + "h " + m + "m " + s.ToString("F1") + "s";

-            }

-

-            if (m > 0)

-            {

-                return m + "m " + s.ToString("F1") + "s";

-            }

-

-            return s.ToString("F1") + "s";

+        public static string ToTime(this float value, string format = "F1")

+        {

+            try

+            {

+                var s = value;

+                var m = 0;

+                var h = 0;

+                var d = 0;

+                var y = 0;

+

+                // Years

+                while (s >= 31536000)

+                {

+                    y++;

+                    s -= 31536000;

+                }

+

+                // Days

+                while (s >= 86400)

+                {

+                    d++;

+                    s -= 86400;

+                }

+

+                // Hours

+                while (s >= 3600)

+                {

+                    h++;

+                    s -= 3600;

+                }

+

+                // Minutes

+                while (s >= 60)

+                {

+                    m++;

+                    s -= 60;

+                }

+

+                if (y > 0)

+                {

+                    return y + "y " + d + "d " + h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (d > 0)

+                {

+                    return d + "d " + h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (h > 0)

+                {

+                    return h + "h " + m + "m " + s.ToString(format) + "s";

+                }

+

+                if (m > 0)

+                {

+                    return m + "m " + s.ToString(format) + "s";

+                }

+

+                return s.ToString(format) + "s";

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "FloatExtensions->ToTime");

+                return "ERR";

+            }

         }

     }

 }

--- a/KerbalEngineer/Flight/Readouts/Orbital/OrbitalPeriod.cs
+++ b/KerbalEngineer/Flight/Readouts/Orbital/OrbitalPeriod.cs
@@ -37,7 +37,7 @@
 

         public override void Draw()

         {

-            this.DrawLine(FlightGlobals.ship_orbit.period.ToTime());

+            this.DrawLine(FlightGlobals.ship_orbit.period.ToTime("F3"));

         }

     }

 }

--- a/KerbalEngineer/Logger.cs
+++ b/KerbalEngineer/Logger.cs
@@ -112,6 +112,16 @@
             }

         }

 

+        public static void Exception(Exception ex, string location)

+        {

+            lock (messages)

+            {

+                messages.Add("[Exception " + DateTime.Now.TimeOfDay + "]: " + location + " // " + ex.Message);

+                messages.Add(ex.StackTrace);

+                messages.Add(string.Empty);

+            }

+        }

+

         #endregion

 

         #region Flushing


 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
--- a/Output/ReadMe.htm
+++ b/Output/ReadMe.htm
@@ -157,7 +157,7 @@
 				<li>

 					1.0.0.0

 					<ul>

-						<li>Initial release.</li>

+						<li>Initial release for public testing.</li>

 					</ul>

 				</li>

 			</ul>