From 8aba04c3a27c0a47efd2624d4ce710cae7ca7639 Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Sun, 1 Dec 2013 21:34:30 +0000
Subject: [PATCH] Reset: change FDM ownership

- make the FDM owned via a SGSharedPtr
- drop some property references explicitly.
---
 src/FDM/fdm_shell.cxx | 31 ++++++++++++++++++++++---------
 src/FDM/fdm_shell.hxx |  3 ++-
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx
index cb3805d7b..dd5de9eb6 100644
--- a/src/FDM/fdm_shell.cxx
+++ b/src/FDM/fdm_shell.cxx
@@ -63,14 +63,13 @@ using std::string;
 
 FDMShell::FDMShell() :
   _tankProperties( fgGetNode("/consumables/fuel", true) ),
-  _impl(NULL),
   _dataLogging(false)
 {
 }
 
 FDMShell::~FDMShell()
 {
-  delete _impl;
+    SG_LOG(SG_GENERAL, SG_INFO, "destorying FDM shell");
 }
 
 void FDMShell::init()
@@ -91,15 +90,29 @@ void FDMShell::init()
   createImplementation();
 }
 
+void FDMShell::shutdown()
+{
+    if (_impl) {
+        fgSetBool("/sim/fdm-initialized", false);
+        _impl->unbind();
+        _impl.clear();
+    }
+    
+    _props.clear();
+    _wind_north.clear();
+    _wind_east.clear();
+    _wind_down.clear();
+    _control_fdm_atmo.clear();
+    _temp_degc.clear();
+    _pressure_inhg.clear();
+    _density_slugft .clear();
+    _data_logging.clear();
+    _replay_master.clear();
+}
+
 void FDMShell::reinit()
 {
-  if (_impl) {
-    fgSetBool("/sim/fdm-initialized", false);
-    _impl->unbind();
-    delete _impl;
-    _impl = NULL;
-  }
-  
+  shutdown();
   init();
 }
 
diff --git a/src/FDM/fdm_shell.hxx b/src/FDM/fdm_shell.hxx
index 9beb293e1..0eb576609 100644
--- a/src/FDM/fdm_shell.hxx
+++ b/src/FDM/fdm_shell.hxx
@@ -44,6 +44,7 @@ public:
   virtual ~FDMShell();
   
   virtual void init();
+  virtual void shutdown();
   virtual void reinit();
   
   virtual void bind();
@@ -57,7 +58,7 @@ private:
   void createImplementation();
   
   TankPropertiesList _tankProperties;
-  FGInterface* _impl;
+  SGSharedPtr<FGInterface> _impl;
   SGPropertyNode_ptr _props; // root property tree for this FDM instance
   bool _dataLogging;