Hello everybody,

I've been looking a bit into the NaN issues. A way to produce them on my
system is to reset JSBSim aircraft, although it happens only about every
fifth time on average, and there are at least two different places in
the code where the NaN finally surfaces, both of which are not the root
cause. For the analysis, I used gdb to run the git version with
--enable-fpe.

For one of the locations (FPE caught in SGIntersect.hxx:754) I could
trace the problem down to JSBSim.cxx. The data members are only
initialized to zero the first time an instance of FGJSBSim is created.
This instance is destroyed during a reset and a new one created, whose
data members contain garbage. One of the entries was ~1e+208 here. It
got squared in the intersect routine, causing the FPE.

The minimal solution for this one is to explicitly set to zero those
data members which will be used later without explicit initialization,
in this case last_hook_tip[] and last_hook_root[], see attached patch.
Though it probably wouldn't hurt to initialize all members.

The second place where an FPE shows is kt_70.cxx:211 which seems to be
the first place where the value of /position/altitude-ft is read after a
reset. In this case, gdb shows
(gdb) p alt_node._ptr->_buffer._M_dataplus._M_p
$4 = 0x7ffff387f278 ""
This looks like a NaN value resulting from garbage being copied over.
Possibly SGPropertyNode (or maybe even any class?) suffers from a
similar problem as FGJSBSim.

However, it is also possible that the problem stems from somewhere else,
as a JSBSim trim report is generated before this FPE which looks like this:
> Failed to get Mach number for given Vc and altitude, Vc unchanged.
> Please mail the set of initial conditions used to [...]
>   Trim Results:
>           Altitude AGL:     15  wdot:       nan Tolerance: 1e-03  Failed
>            Pitch Angle:  0.061  qdot:       nan Tolerance: 1e-04  Failed
>
>   Trim Statistics:
>    Total Iterations: 61
>    Sub-iterations:
>    wdot: 0 average: 0  successful:  0  stability: 100
>    qdot: 0 average: 0  successful:  0  stability: 100
>    Run Count: 36800
This could have to do with the Mach calculation routine failing, but I'm
far from sure on this, as Vc is zero. If it does, however, maybe
Bertrand's recent changes to JSBSim CVS improve the situation.

So this is about what I found out until now, I'll try to keep looking
further into this. Can anybody point me to some documentation about how
initialization of class members is supposed to happen the right way?

Best regards,
        Andreas
commit 6391bf6516cd1a9461e8c6a30252098fc96efcc8
Author: Andreas Gaeb <[email protected]>
Date:   Sat Jan 22 17:10:02 2011 +0100

    JSBSim.cxx: initialize array members to zero

diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx
index d92d265..8463ef5 100644
--- a/src/FDM/JSBSim/JSBSim.cxx
+++ b/src/FDM/JSBSim/JSBSim.cxx
@@ -292,6 +292,8 @@ FGJSBsim::FGJSBsim( double dt )
         fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-x-in", 196),
         fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-y-in", 0),
         fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-z-in", -16));
+    last_hook_tip[0] = 0; last_hook_tip[1] = 0; last_hook_tip[2] = 0;
+    last_hook_root[0] = 0; last_hook_root[1] = 0; last_hook_root[2] = 0;
 
     crashed = false;
 }
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to