Unbind FGAtmosphere properties#902
Conversation
Codecov Report
@@ Coverage Diff @@
## master #902 +/- ##
==========================================
+ Coverage 23.09% 23.16% +0.07%
==========================================
Files 167 167
Lines 19626 19644 +18
==========================================
+ Hits 4533 4551 +18
Misses 15093 15093
|
|
Assuming we're not planning on allowing a user to switch atmospheric models part-way through a simulation, i.e. a single atmospheric model is chosen/set at startup then instead of having to handle, binding, unbinding, binding again can't we simply create the relevant instance of the atmosphere model at: Line 229 in 39e7058 |
I confirm there is no such plan.
Unfortunately we can't because the line you mentioned is called from the |
As I mentioned previously in #885 (comment), I'm currently working on adding the NRLMSIS2.0 atmospheric model to JSBSim which is kind of a revival of the existing
src/models/atmosphere/FGMSIS.cppcode (which was based on the previous version 1.0 of NRLMSIS)1.In order for this feature to work, we will need to modify the atmosphere model that is currently created by default in
FGFDMExec:jsbsim/src/FGFDMExec.cpp
Line 229 in 39e7058
Basically, the idea is to call at some point the following code:
The trick is that if no special care is taken, the properties
atmosphere/T-R,atmosphere/P-Psf, etc. will still be bound to the old instance ofFGStandardAtmosphereeven after the above code has been executed. With the current code,FGMSISwould fail to bind itself to the aforementioned properties as they would already be tied toFGStandardAtmosphereand JSBSim would complain with the infamous error messageFailed to tie property atmosphere/T-R to object methods. Even worse, if one would try to accessatmosphere/T-Rand the likes, it would cause a SEGFAULT as the property would try to call the methodFGAtmosphere::GetTemperature()on a deletedFGStandardAtmopshereinstance.To avoid this issue, we need to tell JSBSim to unbind
FGStandardAtmospherebefore an instance ofFGMSISis created. Currently there is no generic code in JSBSim that allows to unbind a singleFGModelinstance (you'd need to untie the properties one by one which is less than ideal from a maintenance standpoint).To address this issue the current PR adds a new method
FGPropertyManager::Unbind(void* instance)to unbind the properties of a given class instance. With this new method, the code above will become something like:The new
Unbindmethod also restores the read/write attributes of each properties as the newly bound instance might want to set them differently.Finally, the unit test
FGAtmosphereTestis amended by the PR to test the new feature and checks that the properties suchatmosphere/T-Rare tied to the correct instance (see the methodtestRun()inFGAmosphereTest).Footnotes
For the record the code in
FGMSIS.cppis dead code as there is currently no means to execute this code from JSBSim. ↩