VOID_DataLogger: Add a null gate in CloseFileIfOpen.
VOID_DataLogger: Add a null gate in CloseFileIfOpen.

--- a/VOIDEditorMaster.cs
+++ b/VOIDEditorMaster.cs
@@ -105,6 +105,26 @@
 
 			this.Core.OnGUI();
 		}
+
+		public void OnDestroy()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnDestroy();
+		}
+
+		public void OnApplicationQuit()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnApplicationQuit();
+		}
 	}
 }
 

--- a/VOIDFlightMaster.cs
+++ b/VOIDFlightMaster.cs
@@ -104,6 +104,26 @@
 
 			this.Core.OnGUI();
 		}
+
+		public void OnDestroy()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnDestroy();
+		}
+
+		public void OnApplicationQuit()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnApplicationQuit();
+		}
     }
 }
 

--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -180,6 +180,12 @@
 		internal ApplicationLauncherButton AppLauncherButton;
 
 		/*
+		 * Events
+		 * */
+		public delegate void VOIDEventHandler(object sender);
+		public event VOIDEventHandler onApplicationQuit;
+
+		/*
 		 * Properties
 		 * */
 		public bool factoryReset
@@ -625,6 +631,11 @@
 			}
 		}
 
+		public void OnApplicationQuit()
+		{
+			this.onApplicationQuit(this);
+		}
+
 		public void ResetGUI()
 		{
 			this.StopGUI();

--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -425,7 +425,7 @@
 
 			logger.AppendFormat("Cleaning up file {0}...", this.fileName);
 
-			if (this.csvBytes.Count > 0)
+			if (this.csvBytes != null && this.csvBytes.Count > 0)
 			{
 				logger.Append(" Writing remaining data...");
 				this.AsyncWriteData();
@@ -466,6 +466,11 @@
 
 			this.WindowPos.x = Screen.width - 520f;
 			this.WindowPos.y = 85f;
+
+			this.core.onApplicationQuit += delegate(object sender)
+			{
+				this.CloseFileIfOpen();
+			};
 		}
 
 		~VOID_DataLogger()

--- a/VOID_Tools.cs
+++ b/VOID_Tools.cs
@@ -335,7 +335,7 @@
 						func(id);
 					}
 					#if DEBUG
-					catch (ArgumentException ex)
+					catch (ArgumentException)
 					#else
 					catch (ArgumentException)
 					#endif