From a90a24d9dd00b90e098e83530a12c911c4f1ae47 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 5 Jun 2007 16:01:43 +0000 Subject: [PATCH] Maik: fix crash when using aircraft with hitches under the command line solver. (He promises to get all the MP interaction out of the FDM in a future patch.) --- src/FDM/YASim/Hitch.cpp | 170 +++++++++++++++++++++------------------- src/FDM/YASim/Rotor.cpp | 16 ++-- 2 files changed, 98 insertions(+), 88 deletions(-) diff --git a/src/FDM/YASim/Hitch.cpp b/src/FDM/YASim/Hitch.cpp index 96268e8a8..121486b98 100755 --- a/src/FDM/YASim/Hitch.cpp +++ b/src/FDM/YASim/Hitch.cpp @@ -10,7 +10,9 @@ namespace yasim { Hitch::Hitch(const char *name) { - _node = fgGetNode("/sim/hitches", true)->getNode(name, true); + if (fgGetNode("/sim/hitches", true)) + _node = fgGetNode("/sim/hitches", true)->getNode(name, true); + else _node = 0; int i; for(i=0; i<3; i++) _pos[i] = _force[i] = _winchPos[i] = _mp_lpos[i]=_towEndForce[i]=_mp_force[i]=0; @@ -59,91 +61,95 @@ Hitch::Hitch(const char *name) _mp_is_slave=false; _mp_open_last_state=false; _timeLagCorrectedDist=0; - - _node->tie("tow/length",SGRawValuePointer(&_towLength)); - _node->tie("tow/elastic-constant",SGRawValuePointer(&_towElasticConstant)); - _node->tie("tow/weight-per-m-kg-m",SGRawValuePointer(&_towWeightPerM)); - _node->tie("tow/brake-force",SGRawValuePointer(&_towBrakeForce)); - _node->tie("winch/max-speed-m-s",SGRawValuePointer(&_winchMaxSpeed)); - _node->tie("winch/rel-speed",SGRawValuePointer(&_winchRelSpeed)); - _node->tie("winch/initial-tow-length-m",SGRawValuePointer(&_winchInitialTowLength)); - _node->tie("winch/min-tow-length-m",SGRawValuePointer(&_winchMinTowLength)); - _node->tie("winch/max-tow-length-m",SGRawValuePointer(&_winchMaxTowLength)); - _node->tie("winch/global-pos-x",SGRawValuePointer(&_winchPos[0])); - _node->tie("winch/global-pos-y",SGRawValuePointer(&_winchPos[1])); - _node->tie("winch/global-pos-z",SGRawValuePointer(&_winchPos[2])); - _node->tie("winch/max-power",SGRawValuePointer(&_winchPower)); - _node->tie("winch/max-force",SGRawValuePointer(&_winchMaxForce)); - _node->tie("winch/actual-force",SGRawValuePointer(&_winchActualForce)); - _node->tie("tow/end-force-x",SGRawValuePointer(&_reportTowEndForce[0])); - _node->tie("tow/end-force-y",SGRawValuePointer(&_reportTowEndForce[1])); - _node->tie("tow/end-force-z",SGRawValuePointer(&_reportTowEndForce[2])); - _node->tie("force",SGRawValuePointer(&_forceMagnitude)); - _node->tie("open",SGRawValuePointer(&_open)); - _node->tie("force-is-calculated-by-other",SGRawValuePointer(&_forceIsCalculatedByMaster)); - _node->tie("local-pos-x",SGRawValuePointer(&_pos[0])); - _node->tie("local-pos-y",SGRawValuePointer(&_pos[1])); - _node->tie("local-pos-z",SGRawValuePointer(&_pos[2])); - _node->tie("tow/dist",SGRawValuePointer(&_dist)); - _node->tie("tow/dist-time-lag-corrected",SGRawValuePointer(&_timeLagCorrectedDist)); - _node->tie("tow/connected-to-property-node",SGRawValuePointer(&_towEndIsConnectedToProperty)); - _node->tie("tow/connected-to-mp-node",SGRawValuePointer(&_nodeIsMultiplayer)); - _node->tie("tow/connected-to-ai-node",SGRawValuePointer(&_nodeIsAiAircraft)); - _node->tie("tow/connected-to-ai-or-mp-id",SGRawValuePointer(&_nodeID)); - _node->tie("debug/hitch-height-above-ground",SGRawValuePointer(&_height_above_ground)); - _node->tie("debug/tow-end-height-above-ground",SGRawValuePointer(&_winch_height_above_ground)); - _node->tie("debug/tow-rel-lo-pos",SGRawValuePointer(&_loPosFrac)); - _node->tie("debug/tow-lowest-pos-height",SGRawValuePointer(&_lowest_tow_height)); - _node->tie("is-slave",SGRawValuePointer(&_isSlave)); - _node->tie("speed-in-tow-direction",SGRawValuePointer(&_speed_in_tow_direction)); - _node->tie("mp-auto-connect-period",SGRawValuePointer(&_mpAutoConnectPeriod)); - _node->tie("mp-time-lag",SGRawValuePointer(&_mp_time_lag)); - _node->setStringValue("tow/node",""); - _node->setStringValue("tow/connected-to-ai-or-mp-callsign"); - _node->setBoolValue("broken",false); + if (_node) + { + _node->tie("tow/length",SGRawValuePointer(&_towLength)); + _node->tie("tow/elastic-constant",SGRawValuePointer(&_towElasticConstant)); + _node->tie("tow/weight-per-m-kg-m",SGRawValuePointer(&_towWeightPerM)); + _node->tie("tow/brake-force",SGRawValuePointer(&_towBrakeForce)); + _node->tie("winch/max-speed-m-s",SGRawValuePointer(&_winchMaxSpeed)); + _node->tie("winch/rel-speed",SGRawValuePointer(&_winchRelSpeed)); + _node->tie("winch/initial-tow-length-m",SGRawValuePointer(&_winchInitialTowLength)); + _node->tie("winch/min-tow-length-m",SGRawValuePointer(&_winchMinTowLength)); + _node->tie("winch/max-tow-length-m",SGRawValuePointer(&_winchMaxTowLength)); + _node->tie("winch/global-pos-x",SGRawValuePointer(&_winchPos[0])); + _node->tie("winch/global-pos-y",SGRawValuePointer(&_winchPos[1])); + _node->tie("winch/global-pos-z",SGRawValuePointer(&_winchPos[2])); + _node->tie("winch/max-power",SGRawValuePointer(&_winchPower)); + _node->tie("winch/max-force",SGRawValuePointer(&_winchMaxForce)); + _node->tie("winch/actual-force",SGRawValuePointer(&_winchActualForce)); + _node->tie("tow/end-force-x",SGRawValuePointer(&_reportTowEndForce[0])); + _node->tie("tow/end-force-y",SGRawValuePointer(&_reportTowEndForce[1])); + _node->tie("tow/end-force-z",SGRawValuePointer(&_reportTowEndForce[2])); + _node->tie("force",SGRawValuePointer(&_forceMagnitude)); + _node->tie("open",SGRawValuePointer(&_open)); + _node->tie("force-is-calculated-by-other",SGRawValuePointer(&_forceIsCalculatedByMaster)); + _node->tie("local-pos-x",SGRawValuePointer(&_pos[0])); + _node->tie("local-pos-y",SGRawValuePointer(&_pos[1])); + _node->tie("local-pos-z",SGRawValuePointer(&_pos[2])); + _node->tie("tow/dist",SGRawValuePointer(&_dist)); + _node->tie("tow/dist-time-lag-corrected",SGRawValuePointer(&_timeLagCorrectedDist)); + _node->tie("tow/connected-to-property-node",SGRawValuePointer(&_towEndIsConnectedToProperty)); + _node->tie("tow/connected-to-mp-node",SGRawValuePointer(&_nodeIsMultiplayer)); + _node->tie("tow/connected-to-ai-node",SGRawValuePointer(&_nodeIsAiAircraft)); + _node->tie("tow/connected-to-ai-or-mp-id",SGRawValuePointer(&_nodeID)); + _node->tie("debug/hitch-height-above-ground",SGRawValuePointer(&_height_above_ground)); + _node->tie("debug/tow-end-height-above-ground",SGRawValuePointer(&_winch_height_above_ground)); + _node->tie("debug/tow-rel-lo-pos",SGRawValuePointer(&_loPosFrac)); + _node->tie("debug/tow-lowest-pos-height",SGRawValuePointer(&_lowest_tow_height)); + _node->tie("is-slave",SGRawValuePointer(&_isSlave)); + _node->tie("speed-in-tow-direction",SGRawValuePointer(&_speed_in_tow_direction)); + _node->tie("mp-auto-connect-period",SGRawValuePointer(&_mpAutoConnectPeriod)); + _node->tie("mp-time-lag",SGRawValuePointer(&_mp_time_lag)); + _node->setStringValue("tow/node",""); + _node->setStringValue("tow/connected-to-ai-or-mp-callsign"); + _node->setBoolValue("broken",false); + } } Hitch::~Hitch() { - _node->untie("tow/length"); - _node->untie("tow/elastic-constant"); - _node->untie("tow/weight-per-m-kg-m"); - _node->untie("tow/brake-force"); - _node->untie("winch/max-speed-m-s"); - _node->untie("winch/rel-speed"); - _node->untie("winch/initial-tow-length-m"); - _node->untie("winch/min-tow-length-m"); - _node->untie("winch/max-tow-length-m"); - _node->untie("winch/global-pos-x"); - _node->untie("winch/global-pos-y"); - _node->untie("winch/global-pos-z"); - _node->untie("winch/max-power"); - _node->untie("winch/max-force"); - _node->untie("winch/actual-force"); - _node->untie("tow/end-force-x"); - _node->untie("tow/end-force-y"); - _node->untie("tow/end-force-z"); - _node->untie("force"); - _node->untie("open"); - _node->untie("force-is-calculated-by-other"); - _node->untie("local-pos-x"); - _node->untie("local-pos-y"); - _node->untie("local-pos-z"); - _node->untie("tow/dist"); - _node->untie("tow/dist-time-lag-corrected"); - _node->untie("tow/connected-to-property-node"); - _node->untie("tow/connected-to-mp-node"); - _node->untie("tow/connected-to-ai-node"); - _node->untie("tow/connected-to-ai-or-mp-id"); - _node->untie("debug/hitch-height-above-ground"); - _node->untie("debug/tow-end-height-above-ground"); - _node->untie("debug/tow-rel-lo-pos"); - _node->untie("debug/tow-lowest-pos-height"); - _node->untie("is-slave"); - _node->untie("speed-in-tow-direction"); - _node->untie("mp-auto-connect-period"); - _node->untie("mp-time-lag"); - + if (_node) + { + _node->untie("tow/length"); + _node->untie("tow/elastic-constant"); + _node->untie("tow/weight-per-m-kg-m"); + _node->untie("tow/brake-force"); + _node->untie("winch/max-speed-m-s"); + _node->untie("winch/rel-speed"); + _node->untie("winch/initial-tow-length-m"); + _node->untie("winch/min-tow-length-m"); + _node->untie("winch/max-tow-length-m"); + _node->untie("winch/global-pos-x"); + _node->untie("winch/global-pos-y"); + _node->untie("winch/global-pos-z"); + _node->untie("winch/max-power"); + _node->untie("winch/max-force"); + _node->untie("winch/actual-force"); + _node->untie("tow/end-force-x"); + _node->untie("tow/end-force-y"); + _node->untie("tow/end-force-z"); + _node->untie("force"); + _node->untie("open"); + _node->untie("force-is-calculated-by-other"); + _node->untie("local-pos-x"); + _node->untie("local-pos-y"); + _node->untie("local-pos-z"); + _node->untie("tow/dist"); + _node->untie("tow/dist-time-lag-corrected"); + _node->untie("tow/connected-to-property-node"); + _node->untie("tow/connected-to-mp-node"); + _node->untie("tow/connected-to-ai-node"); + _node->untie("tow/connected-to-ai-or-mp-id"); + _node->untie("debug/hitch-height-above-ground"); + _node->untie("debug/tow-end-height-above-ground"); + _node->untie("debug/tow-rel-lo-pos"); + _node->untie("debug/tow-lowest-pos-height"); + _node->untie("is-slave"); + _node->untie("speed-in-tow-direction"); + _node->untie("mp-auto-connect-period"); + _node->untie("mp-time-lag"); + } delete _state; } diff --git a/src/FDM/YASim/Rotor.cpp b/src/FDM/YASim/Rotor.cpp index 0e59f6610..83a57b839 100644 --- a/src/FDM/YASim/Rotor.cpp +++ b/src/FDM/YASim/Rotor.cpp @@ -359,12 +359,14 @@ void Rotorgear::setEngineOn(int value) void Rotorgear::setRotorEngineMaxRelTorque(float lval) { - fgGetNode("/rotors/gear/max-rel-torque", true)->setDoubleValue(lval); + SGPropertyNode * node = fgGetNode("/rotors/gear/max-rel-torque", true); + if (node) node->setDoubleValue(lval); } void Rotorgear::setRotorRelTarget(float lval) { - fgGetNode("/rotors/gear/target-rel-rpm", true)->setDoubleValue(lval); + SGPropertyNode * node = fgGetNode("/rotors/gear/target-rel-rpm", true); + if (node) node->setDoubleValue(lval); } void Rotor::setAlpha0(float f) @@ -1376,10 +1378,10 @@ void Rotorgear::calcForces(float* torqueOut) } float max_torque_of_engine=0; SGPropertyNode * node=fgGetNode("/rotors/gear", true); - float target_rel_rpm=node->getDoubleValue("target-rel-rpm",1); + float target_rel_rpm=(node==0?1:node->getDoubleValue("target-rel-rpm",1)); if (_engineon) { - float max_rel_torque=node->getDoubleValue("max-rel-torque",1); + float max_rel_torque=(node==0?1:node->getDoubleValue("max-rel-torque",1)); max_torque_of_engine=_max_power_engine*max_rel_torque; float df=target_rel_rpm-omegarel; df/=_engine_prop_factor; @@ -1473,8 +1475,10 @@ void Rotorgear::compile() Rotor* r = (Rotor*)_rotors.get(j); r->compile(); } - fgGetNode("/rotors/gear/target-rel-rpm", true)->setDoubleValue(1); - fgGetNode("/rotors/gear/max-rel-torque", true)->setDoubleValue(1); + SGPropertyNode * node = fgGetNode("/rotors/gear/target-rel-rpm", true); + if (node) node->setDoubleValue(1); + node =fgGetNode("/rotors/gear/max-rel-torque", true); + if (node) node->setDoubleValue(1); } void Rotorgear::getDownWash(float *pos, float * v_heli, float *downwash) -- 2.39.5