From 738d653745142f61ddcf1f4845532135f29dc8fa Mon Sep 17 00:00:00 2001 From: James Turner <zakalawe@mac.com> Date: Fri, 31 Dec 2010 18:26:23 +0000 Subject: [PATCH] Work-around for bug #222 - delete the units/WOW property on init. Another cleanup --- src/FDM/JSBSim/JSBSim.cxx | 28 +++++++++++++++++++++------- src/FDM/JSBSim/JSBSim.hxx | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 15b575123..d92d265f0 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -143,6 +143,8 @@ FGJSBsim::FGJSBsim( double dt ) break; } } + + resetPropertyState(); fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() ); @@ -298,13 +300,6 @@ FGJSBsim::FGJSBsim( double dt ) FGJSBsim::~FGJSBsim(void) { delete fdmex; - - SGPropertyNode_ptr jsbsimRoot = fgGetNode("/fdm/jsbsim"); - if (jsbsimRoot) { - SGPropertyNode* fdm = jsbsimRoot->getParent(); - fdm->removeChild("jsbsim", 0, false); - } - // properties are deleted when the sharedPtr above goes away } /******************************************************************************/ @@ -1418,3 +1413,22 @@ 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 6729a141f..1a8037167 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -284,6 +284,7 @@ private: void update_external_forces(double t_off); + void resetPropertyState(); };