1
0
Fork 0

Fixed a segfault occuring when changing the LOD ranges with a JSBSim aircraft.

Bug report and testing by Jonathan Redpath (see details in issue #276 at GitHub).

The check of FGInterface::get_agl_ft return value has been discarded a few years ago (commit 86b346) on the ground that the method was returning a meaningful altitude above ground level even if it failed.
See mailing lists discussions:
https://sourceforge.net/p/flightgear/mailman/message/32246380/
https://sourceforge.net/p/flightgear/mailman/message/32247050/

There is no indication however that the other parameters are populated with meaningful values when FGInterface::get_agl_ft reports an error. The returned `material` pointer is therefore discarded when an error is reported. Ground reactions are still processed in all cases as was decided in 2014.

Took the opportunity to initialize the `material` pointer to null, to avoid yet another problem with unitialized values.
This commit is contained in:
Bertrand Coconnier 2020-04-30 15:25:22 +02:00
parent 7f319d69ca
commit ca8fffda3e

View file

@ -1378,14 +1378,13 @@ FGJSBsim::get_agl_ft(double t, const FGColumnVector3& loc, double alt_off,
double contact[3], double normal[3], double vel[3],
double angularVel[3])
{
const simgear::BVHMaterial* material;
const simgear::BVHMaterial* material = nullptr;
simgear::BVHNode::Id id;
double pt[3] {loc(1), loc(2), loc(3)};
// don't check the return value and continue above scenery discontinuity
// see http://osdir.com/ml/flightgear-sim/2014-04/msg00145.html
FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel,
angularVel, material, id);
if (!FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel,
angularVel, material, id))
material = nullptr; // Discard the material data when FGInterface reports an problem.
SGGeod geodPt = SGGeod::fromCart(SG_FEET_TO_METER*SGVec3d(pt));
SGQuatd hlToEc = SGQuatd::fromLonLat(geodPt);