From fba1e9fa61466b25e4611f65b0281e7bae4fa167 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 21 Apr 2021 21:56:33 +0100 Subject: [PATCH] YASim: fix warnings from bind() Add a version of fgUntie which is quiet, if the property does not currently exist. --- src/FDM/YASim/YASim.cxx | 15 ++++++++++----- src/Main/fg_props.cxx | 16 ++++++++++++++++ src/Main/fg_props.hxx | 4 ++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index 9e4b50ba0..1647ddca7 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -94,11 +94,16 @@ void YASim::bind() char buf[256]; for(int i=0; i<_fdm->getAirplane()->getModel()->numThrusters(); i++) { - sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i); fgUntie(buf); - sprintf(buf, "/engines/engine[%d]/rpm", i); fgUntie(buf); - sprintf(buf, "/engines/engine[%d]/mp-osi", i); fgUntie(buf); - sprintf(buf, "/engines/engine[%d]/egt-degf", i); fgUntie(buf); - sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i); fgUntie(buf); + sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i); + fgUntieIfDefined(buf); + sprintf(buf, "/engines/engine[%d]/rpm", i); + fgUntieIfDefined(buf); + sprintf(buf, "/engines/engine[%d]/mp-osi", i); + fgUntieIfDefined(buf); + sprintf(buf, "/engines/engine[%d]/egt-degf", i); + fgUntieIfDefined(buf); + sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i); + fgUntieIfDefined(buf); } } diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 4679a752e..6218ac571 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -720,5 +720,21 @@ fgUntie(const char * name) } } +void fgUntieIfDefined(const std::string& name) +{ + SGPropertyNode* node = globals->get_props()->getNode(name); + if (!node) { + return; + } + + if (!node->isTied()) { + return; + } + + if (!node->untie()) { + SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name); + } +} + // end of fg_props.cxx diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 894f69e4d..2ec24f770 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -716,6 +716,10 @@ extern void fgSetWritable (const char * name, bool state = true); */ extern void fgUntie (const char * name); +/** + @brfief variant of the above which doesn't warn if the property does not exist + */ +void fgUntieIfDefined(const std::string& name); /** * Tie a property to a pair of simple functions.