From 13bb1adf54102783fb492172f9f29630f5e3dce1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 31 May 2020 12:24:36 +0100 Subject: [PATCH] Better fix for orientation nodes init (Avoid the chance that we overwrite a value set earlier) --- src/Main/fg_props.cxx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 9c1cc7e18..62906050e 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -373,6 +373,15 @@ FGProperties::init () { } +static SGPropertyNode_ptr initDoubleNode(const std::string& path, const double v) +{ + auto r = fgGetNode(path, true); + if (r->getType() == simgear::props::NONE) { + r->setDoubleValue(v); + } + return r; +} + void FGProperties::bind () { @@ -417,20 +426,11 @@ FGProperties::bind () _tiedProperties.Tie("/position/latitude-string", getLatitudeString); _tiedProperties.Tie("/position/longitude-string", getLongitudeString); - _headingMagnetic = fgGetNode("/orientation/heading-magnetic-deg", true); - _headingMagnetic->setDoubleValue(0.0); - - _trackMagnetic = fgGetNode("/orientation/track-magnetic-deg", true); - _trackMagnetic->setDoubleValue(0.0); - - _magVar = fgGetNode("/environment/magnetic-variation-deg", true); - _magVar->setDoubleValue(0.0); - - _trueHeading = fgGetNode("/orientation/heading-deg", true); - _trueHeading->setDoubleValue(0.0); - - _trueTrack = fgGetNode("/orientation/track-deg", true); - _trueTrack->setDoubleValue(0.0); + _headingMagnetic = initDoubleNode("/orientation/heading-magnetic-deg", 0.0); + _trackMagnetic = initDoubleNode("/orientation/track-magnetic-deg", 0.0); + _magVar = initDoubleNode("/environment/magnetic-variation-deg", 0.0); + _trueHeading = initDoubleNode("/orientation/heading-deg", 0.0); + _trueTrack = initDoubleNode("/orientation/track-deg", 0.0); } void