Hi all,

I think I have a final bug fix for JSBSim reset issues (bug #204 and
#222). I have investigated James Turner's fix and tried to understand
why it fixes the issue in every case but for gliders.

NaNs (bug #222) were basically generated because the method
JSBSim::unbind() was not implemented in JSBSim.cxx. Thus when
globals->get_subsystem("flight")->unbind(); (src/Main/fg_init.cxx line
1538) was executed, FG properties were unbound but JSBSim properties
were not. The NaNs were then triggered afterwards when
globals->restoreInitialState(); was called because JSBSim listeners
were still active and triggered the execution of routines (trim for
instance) which should not have been called at this stage of the reset
process. By implementing the unbind() method in JSBSim.cxx, there are
no listeners remaining when restoreInitialState is called and JSBSim
routines are no longer unexpectedly called.

The second bug "Tried to initialize a non-existent engine" is removed
by setting the useDefault parameter to false when calling
FGPropertyManager::Tie() in src/FDM/JSBSim/models/FGPropulsion.cpp
line 649. This bug was triggered because the tie() method of
SGPropertyNode remembers the setter/getter that were set on the
property "propulsion/set-running" when it was created. When FG is
resetting, JSBSim re-builds this property. When asked to re-use the
default value, SGPropertyNode::tie() calls the setter of the property
"propulsion/set-running" which is InitRunning() in this case. Because
no engines are created yet, InitRunning() complains that we are trying
"to initialize a non-existent engine". The simplest way to fix this
bug is to ask SGPropertyNode::tie() not to set
"propulsion/set-running" to its default value. That prevents the
setter InitRunning() to be called.

As far as I can see, JSBSim uses SGPropertyNode::Tie() with useDefault
set to true in many places. This may be a potential source of similar
bugs in other places. I wonder if JSBSim should not better set
useDefault to false instead ? But that is a topic for JSBSim
developers mailing list.

Cheers,

Bertrand.


2011/1/28 henri orange <hohora...@gmail.com>:
> Continued
>
> I can notice, the older fgfs version without James Turner Patch, was right
> with Gliders ( no Engines ).
> My conclusion,
> the James Turner Patch was right to solve the issue, Aircraft with engine
> related,
> however
> it makes an issue, Aircraft without  engine related.
> Sorry James, your patch does not fix correctly the bug.
>
> 2011/1/28 henri orange <hohora...@gmail.com>
>>
>> BTW: paraglider is getting the same issue
>>
>> 2011/1/28 henri orange <hohora...@gmail.com>
>>>
>>> Hello devel members,
>>>
>>> Again, the issue .
>>> Not with  Aircraft's Engine, since the patch solved it (though getting
>>> others randomly bugs)
>>> but with Aircraft  WITHOUT  Engine, like Gliders .
>>> Tested with sgs233.
>>> Whould be the same issue with others JSBSim gliders
>>>
>>>
>>>
>>> 2011/1/25 James Turner <zakal...@mac.com>
>>>>
>>>> On 25 Jan 2011, at 10:28, Jon S. Berndt wrote:
>>>>
>>>> > What patch?
>>>>
>>>> FIx for #204, the issue Henri is describing:
>>>>
>>>>
>>>> http://gitorious.org/fg/flightgear/commit/c2458a17bf0a8a95caf1a43e37482162ae0100bc
>>>>
>>>> Partial band-aid for #222, the reset-NaN crash: (ugly, but not in the
>>>> main JSBSim code)
>>>>
>>>>
>>>> http://gitorious.org/fg/flightgear/commit/4b494b1d0842bc53d7295f74c44cf4f7a3185446
>>>>
>>>> Andreas' other fixes for #222:
>>>>
>>>>
>>>> http://gitorious.org/fg/flightgear/commit/4f364af6d178d947eae1a5a751e3a9542b270069
>>>>
>>>> Regards,
>>>> James
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
>>>> Finally, a world-class log management solution at an even better
>>>> price-free!
>>>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
>>>> February 28th, so secure your free ArcSight Logger TODAY!
>>>> http://p.sf.net/sfu/arcsight-sfd2d
>>>> _______________________________________________
>>>> Flightgear-devel mailing list
>>>> Flightgear-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/flightgear-devel
>>>
>>>
>>>
>>> --
>>> Best regards,
>>>
>>> Henri, aka Alva
>>> Official grtux hangar maintainer
>>>
>>
>>
>>
>> --
>> Best regards,
>>
>> Henri, aka Alva
>> Official grtux hangar maintainer
>>
>
>
>
> --
> Best regards,
>
> Henri, aka Alva
> Official grtux hangar maintainer
>
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> Flightgear-devel mailing list
> Flightgear-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/flightgear-devel
>
>
diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx
index f802c8c..a9e9be7 100644
--- a/src/FDM/JSBSim/JSBSim.cxx
+++ b/src/FDM/JSBSim/JSBSim.cxx
@@ -144,8 +144,6 @@ FGJSBsim::FGJSBsim( double dt )
         }
     }
 
-    resetPropertyState();
-    
     fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
 
     // Register ground callback.
@@ -424,6 +422,33 @@ void FGJSBsim::init()
 
 /******************************************************************************/
 
+void checkTied ( FGPropertyManager *node )
+{
+  int N = node->nChildren();
+  string name;
+
+  for (int i=0; i<N; i++) {
+    if (node->getChild(i)->nChildren() ) {
+      checkTied( (FGPropertyManager*)node->getChild(i) );
+    }
+    if ( node->getChild(i)->isTied() ) {
+      name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
+      node->Untie(name);
+    }
+  }
+}
+
+/******************************************************************************/
+
+void FGJSBsim::unbind()
+{
+  SGPropertyNode* instance = globals->get_props()->getNode("/fdm/jsbsim");
+  checkTied((FGPropertyManager*)instance);
+  FGInterface::unbind();
+}
+
+/******************************************************************************/
+
 // Run an iteration of the EOM (equations of motion)
 
 void FGJSBsim::update( double dt )
@@ -1415,21 +1440,3 @@ void FGJSBsim::update_external_forces(double t_off)
     fgSetDouble("/fdm/jsbsim/systems/hook/tailhook-pos-deg", fi);
 }
 
-void FGJSBsim::resetPropertyState()
-{
-// this code works-around bug #222:
-// http://code.google.com/p/flightgear-bugs/issues/detail?id=222
-// for whatever reason, having an existing value for the WOW
-// property causes the NaNs. Should that be fixed, this code can die
-  SGPropertyNode* gear = fgGetNode("/fdm/jsbsim/gear", false);
-  if (!gear) {
-    return;
-  }
-  
-  int index = 0;
-  SGPropertyNode* unitNode = NULL;
-  for (; (unitNode = gear->getChild("unit", index)) != NULL; ++index) {
-    unitNode->removeChild("WOW", 0, false);
-  }
-}
-
diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx
index 1a80371..a01146b 100644
--- a/src/FDM/JSBSim/JSBSim.hxx
+++ b/src/FDM/JSBSim/JSBSim.hxx
@@ -110,6 +110,9 @@ public:
     /// Reset flight params to a specific position
     void init();
 
+    /// Unbind properties
+    void unbind();
+
     /// @name Position Parameter Set
     //@{
     /** Set geocentric latitude
@@ -283,8 +286,6 @@ private:
     void update_gear(void);
 
     void update_external_forces(double t_off);
-
-    void resetPropertyState();
 };
 
 
diff --git a/src/FDM/JSBSim/models/FGPropulsion.cpp b/src/FDM/JSBSim/models/FGPropulsion.cpp
index 57d2852..05a2da4 100644
--- a/src/FDM/JSBSim/models/FGPropulsion.cpp
+++ b/src/FDM/JSBSim/models/FGPropulsion.cpp
@@ -307,18 +307,23 @@ bool FGPropulsion::Load(Element* el)
     try {
       if (type == "piston_engine") {
         HavePistonEngine = true;
+        if (!IsBound) bind();
         Engines.push_back(new FGPiston(FDMExec, document, numEngines));
       } else if (type == "turbine_engine") {
         HaveTurbineEngine = true;
+        if (!IsBound) bind();
         Engines.push_back(new FGTurbine(FDMExec, document, numEngines));
       } else if (type == "turboprop_engine") {
         HaveTurboPropEngine = true;
+        if (!IsBound) bind();
         Engines.push_back(new FGTurboProp(FDMExec, document, numEngines));
       } else if (type == "rocket_engine") {
         HaveRocketEngine = true;
+        if (!IsBound) bind();
         Engines.push_back(new FGRocket(FDMExec, document, numEngines));
       } else if (type == "electric_engine") {
         HaveElectricEngine = true;
+        if (!IsBound) bind();
         Engines.push_back(new FGElectric(FDMExec, document, numEngines));
       } else {
         cerr << "Unknown engine type: " << type << endl;
@@ -345,7 +350,6 @@ bool FGPropulsion::Load(Element* el)
   if (el->FindElement("dump-rate"))
     DumpRate = el->FindElementValueAsNumberConvertTo("dump-rate", "LBS/MIN");
 
-  if (!IsBound) bind();
   PostLoad(el, PropertyManager);
 
   return true;
@@ -642,7 +646,7 @@ void FGPropulsion::bind(void)
   typedef int (FGPropulsion::*iPMF)(void) const;
 
   IsBound = true;
-  PropertyManager->Tie("propulsion/set-running", this, (iPMF)0, &FGPropulsion::InitRunning, true);
+  PropertyManager->Tie("propulsion/set-running", this, (iPMF)0, &FGPropulsion::InitRunning, false);
   if (HaveTurbineEngine) {
     PropertyManager->Tie("propulsion/starter_cmd", this, (iPMF)0, &FGPropulsion::SetStarter,  true);
     PropertyManager->Tie("propulsion/cutoff_cmd", this,  (iPMF)0, &FGPropulsion::SetCutoff,   true);
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to