From 4b494b1d0842bc53d7295f74c44cf4f7a3185446 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 25 Jan 2011 00:25:23 +0000 Subject: [PATCH 1/3] Re-apply partial fix for #222, JSBsim crash-on-reset --- src/FDM/JSBSim/JSBSim.cxx | 20 ++++++++++++++++++++ src/FDM/JSBSim/JSBSim.hxx | 1 + 2 files changed, 21 insertions(+) diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index e8a96c018..18863dbb6 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -144,6 +144,8 @@ FGJSBsim::FGJSBsim( double dt ) } } + resetPropertyState(); + fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() ); // Register ground callback. @@ -1411,3 +1413,21 @@ 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(); }; From c2458a17bf0a8a95caf1a43e37482162ae0100bc Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 25 Jan 2011 00:25:43 +0000 Subject: [PATCH 2/3] Re-apply fix for #204, crash on JSBSim reset --- src/FDM/JSBSim/models/FGPropulsion.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/FDM/JSBSim/models/FGPropulsion.cpp b/src/FDM/JSBSim/models/FGPropulsion.cpp index 32d8b42a1..57d2852f3 100644 --- a/src/FDM/JSBSim/models/FGPropulsion.cpp +++ b/src/FDM/JSBSim/models/FGPropulsion.cpp @@ -307,23 +307,18 @@ 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; @@ -350,6 +345,7 @@ 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; From 4f364af6d178d947eae1a5a751e3a9542b270069 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 25 Jan 2011 00:26:07 +0000 Subject: [PATCH 3/3] Andreas Gaeb: fix #222 (JSBSIm reset problems) --- src/FDM/JSBSim/JSBSim.cxx | 2 ++ src/FDM/JSBSim/models/FGPropagate.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 18863dbb6..f802c8c2e 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -292,6 +292,8 @@ FGJSBsim::FGJSBsim( double dt ) fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-x-in", 196), fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-y-in", 0), fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-z-in", -16)); + last_hook_tip[0] = 0; last_hook_tip[1] = 0; last_hook_tip[2] = 0; + last_hook_root[0] = 0; last_hook_root[1] = 0; last_hook_root[2] = 0; crashed = false; } diff --git a/src/FDM/JSBSim/models/FGPropagate.cpp b/src/FDM/JSBSim/models/FGPropagate.cpp index 8a04cb750..4d1ef44a8 100644 --- a/src/FDM/JSBSim/models/FGPropagate.cpp +++ b/src/FDM/JSBSim/models/FGPropagate.cpp @@ -78,7 +78,8 @@ static const char *IdHdr = ID_PROPAGATE; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGPropagate::FGPropagate(FGFDMExec* fdmex) : FGModel(fdmex) +FGPropagate::FGPropagate(FGFDMExec* fdmex) : FGModel(fdmex), +LocalTerrainRadius(0), SeaLevelRadius(0), VehicleRadius(0) { Debug(0); Name = "FGPropagate";