]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/PropEngine.cpp
FGPUIDialog: fix reading from already free'd memory.
[flightgear.git] / src / FDM / YASim / PropEngine.cpp
index 866ef8165055d2b913f4ee3c3248f5748d196364..c6581f4453e03980c5dab72ae38ad42e9594a02a 100644 (file)
@@ -119,12 +119,22 @@ void PropEngine::stabilize()
 
     bool goingUp = false;
     float step = 10;
-    while(true) {
+
+    // If we cannot manage this in 100 iterations, give up.
+    for (int n = 0; n < 100; n++) {
        float ptau, thrust;
        _prop->calc(_rho, speed, _omega * _gearRatio, &thrust, &ptau);
        _eng->calc(_pressure, _temp, _omega);
         _eng->stabilize();
 
+        // Do it again -- the turbo sets the target MP in the first
+        // run, stabilize sets the current to the target, then we need
+        // to run again to get the correct output torque.  Clumsy, but
+        // it works without side effects (other than solver
+        // performance).  In the future, the Engine objects should
+        // store state to allow them to do the work themselves.
+       _eng->calc(_pressure, _temp, _omega);
+
         // Compute torque as seen by the engine's end of the gearbox.
         // The propeller will be moving more slowly (for gear ratios
         // less than one), so it's torque will be higher than the
@@ -176,6 +186,8 @@ void PropEngine::integrate(float dt)
     _eng->setFuelState(_fuel);
     
     _prop->calc(_rho, speed, _omega * _gearRatio, &thrust, &propTorque);
+    if(_omega == 0.0)
+        _omega = 0.001; // hack to get around reports of NaNs somewhere...
     propTorque *= _gearRatio;
     _eng->calc(_pressure, _temp, _omega);
     _eng->integrate(dt);