You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bug SF2480 has been recently reported in FlightGear which brought to my attention a feature from SGPropertyNode::tie that I think is mostly misused in JSBSim. This feature is the parameter useDefault which allows to keep the existing value from a property when JSBSim ties to the property in question. This feature is used by FGPropertyManager::Tie as well:
* @param useDefault true if any existing property value should be
* copied to the variable; false if the variable should not
* be modified; defaults to true.
*/
void
Tie (const std::string &name, double *pointer, bool useDefault = true);
We have now encountered 2 bugs linked to the usage of that feature (see commits fc9fbda and 9827225) which are basically triggered by a reset in FlightGear and properties tied with useDefault=true.
The reset sequence of FlightGear does not delete the property manager when the instance of JSBSim is destroyed. Then when a property is tied, JSBSim uses the current value of the property whatever it is. I guess the idea is that the value held by the property has been intentionally set to something meaningful prior to the call to tie() and as such should be kept ...which is kind of a leap of faith. On the other hand, when useDefault is set to false, the property value is overwritten by tie() and its previous value is lost which is kind of a hard reset.
Bluntly speaking, I think using this feature is mostly (if not always) a bad idea and is actually a path to disaster: the value held by the property is never validated before calling Tie() so the code is quite trustful to the fact that the value has been set on purpose to something meaningful. But to me, this feature is similar to using uninitialized variables i.e. it may work in most cases - by chance - but it is actually a ticking bomb waiting to blow up to our faces at any random time.
I'll go even farther: I cannot imagine a practical usage to that feature (at least as long as JSBSim is concerned) since FlightGear kills the FDM and reinitializes it from the ground up at each reset. Even worse, some values kept from the previous run might become the seed of future NaNs, who knows ?
My proposal: always set useDefault to false for every single call to SGPropertyNode::tie() that JSBSim makes. What does that mean ? If someone has initialized some properties before JSBSim is initialized then these values will be ignored and overwritten.
I have submitted this idea to the FlightGear mailing list to get some feedback from aircraft modelers.
The text was updated successfully, but these errors were encountered:
Just pushed the commit 193d28c that sets useDefault to false.
We may need to reconsider this position for initial conditions (ic/ properties) in which case this issue shall be re-opened.
The bug SF2480 has been recently reported in FlightGear which brought to my attention a feature from
SGPropertyNode::tie
that I think is mostly misused in JSBSim. This feature is the parameteruseDefault
which allows to keep the existing value from a property when JSBSim ties to the property in question. This feature is used byFGPropertyManager::Tie
as well:jsbsim/src/input_output/FGPropertyManager.h
Lines 500 to 505 in 9827225
We have now encountered 2 bugs linked to the usage of that feature (see commits fc9fbda and 9827225) which are basically triggered by a reset in FlightGear and properties tied with
useDefault=true
.The reset sequence of FlightGear does not delete the property manager when the instance of JSBSim is destroyed. Then when a property is tied, JSBSim uses the current value of the property whatever it is. I guess the idea is that the value held by the property has been intentionally set to something meaningful prior to the call to tie() and as such should be kept ...which is kind of a leap of faith. On the other hand, when
useDefault
is set tofalse
, the property value is overwritten by tie() and its previous value is lost which is kind of a hard reset.Bluntly speaking, I think using this feature is mostly (if not always) a bad idea and is actually a path to disaster: the value held by the property is never validated before calling
Tie()
so the code is quite trustful to the fact that the value has been set on purpose to something meaningful. But to me, this feature is similar to using uninitialized variables i.e. it may work in most cases - by chance - but it is actually a ticking bomb waiting to blow up to our faces at any random time.I'll go even farther: I cannot imagine a practical usage to that feature (at least as long as JSBSim is concerned) since FlightGear kills the FDM and reinitializes it from the ground up at each reset. Even worse, some values kept from the previous run might become the seed of future NaNs, who knows ?
My proposal: always set
useDefault
tofalse
for every single call to SGPropertyNode::tie() that JSBSim makes. What does that mean ? If someone has initialized some properties before JSBSim is initialized then these values will be ignored and overwritten.I have submitted this idea to the FlightGear mailing list to get some feedback from aircraft modelers.
The text was updated successfully, but these errors were encountered: