On Sat, Jan 22, 2011 at 10:36 PM, Andreas Gaeb wrote:

> 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.
>

Excellent! It's a really annoying and persisting problem - though several
related issues were already fixed. Would be great to finally rid this issue
(it's bug #222 http://code.google.com/p/flightgear-bugs/issues/detail?id=222
).

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.
>

Uh, ugly! Why (and where?) are these members only initialized when the first
instance is created? Or are they never initialized and it's just because
memory often happens to be 0 when the first instance is created?


> 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.
>

Definitely a good idea! Uninitialized members easily cause random (=very
ugly) problems - and such issues are a pain to debug. I'm strongly in favour
of initializing all variables/members in the constructor. And especially so
in a case like this, where few objects are created: even if initializing a
certain member wouldn't be necessary, it doesn't cost us much except a few
bytes of code - but no run-time performance at all.

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?
>

Not quite sure what you mean with "the right way". Would be good to
initialize all members in the constructor - with sensible data. I personally
prefer "proper" C++ initializers (where possible), since it's a lot easier
to spot if and which members are initialized, i.e. something like:

MyClass() :
 _member1(NULL),
 _member2(-1),
 ..
{
...
}

Thanks for looking into this issue!

cheers,
Thorsten
------------------------------------------------------------------------------
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
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to