Correct whitespace in NasalPositioned.cxx; fix segfault in NasalPositioned by adding null check in the legGhostGetMember method; add test case for segfault
This commit is contained in:
parent
f6285bc528
commit
b920a09fcf
3 changed files with 109 additions and 77 deletions
|
@ -701,6 +701,12 @@ static const char* legGhostGetMember(naContext c, void* g, naRef field, naRef* o
|
|||
{
|
||||
const char* fieldName = naStr_data(field);
|
||||
FlightPlan::Leg* leg = (FlightPlan::Leg*) g;
|
||||
if (!leg) {
|
||||
*out = naNil();
|
||||
naRuntimeError(c, "leg ghost member fetched, but no associated leg object found");
|
||||
return "";
|
||||
}
|
||||
|
||||
Waypt* wpt = leg->waypoint();
|
||||
|
||||
if (!strcmp(fieldName, "parents")) {
|
||||
|
@ -732,7 +738,11 @@ static const char* legGhostGetMember(naContext c, void* g, naRef field, naRef* o
|
|||
} else if (!strcmp(fieldName, "hold_count")) {
|
||||
*out = naNum(leg->holdCount());
|
||||
} else { // check for fields defined on the underlying waypoint
|
||||
return waypointCommonGetMember(c, wpt, fieldName, out);
|
||||
if (wpt) { // FIXME null check shouldn't be required, check refcount
|
||||
return waypointCommonGetMember(c, wpt, fieldName, out);
|
||||
} else {
|
||||
naRuntimeError(c, "leg ghost member fetched, but no underlying waypoint object found");
|
||||
}
|
||||
}
|
||||
|
||||
return ""; // success
|
||||
|
@ -1366,30 +1376,30 @@ static naRef f_geodtocart(naContext c, naRef me, int argc, naRef* args)
|
|||
*/
|
||||
static naRef f_get_cart_ground_intersection(naContext c, naRef me, int argc, naRef* args)
|
||||
{
|
||||
SGVec3d dir;
|
||||
SGVec3d pos;
|
||||
SGVec3d dir;
|
||||
SGVec3d pos;
|
||||
|
||||
if (argc != 2)
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position: hash{x,y,z}, direction:hash{x,y,z}) expects 2 arguments");
|
||||
if (argc != 2)
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position: hash{x,y,z}, direction:hash{x,y,z}) expects 2 arguments");
|
||||
|
||||
if (!vec3dFromHash(args[0], pos))
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position:hash{x,y,z}, direction:hash{x,y,z}) expects argument(0) to be hash of position containing x,y,z");
|
||||
if (!vec3dFromHash(args[0], pos))
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position:hash{x,y,z}, direction:hash{x,y,z}) expects argument(0) to be hash of position containing x,y,z");
|
||||
|
||||
if (!vec3dFromHash(args[1], dir))
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position: hash{x,y,z}, direction:hash{x,y,z}) expects argument(1) to be hash of direction containing x,y,z");
|
||||
if (!vec3dFromHash(args[1], dir))
|
||||
naRuntimeError(c, "geod_hash get_cart_ground_intersection(position: hash{x,y,z}, direction:hash{x,y,z}) expects argument(1) to be hash of direction containing x,y,z");
|
||||
|
||||
SGVec3d nearestHit;
|
||||
if (!globals->get_scenery()->get_cart_ground_intersection(pos, dir, nearestHit))
|
||||
return naNil();
|
||||
SGVec3d nearestHit;
|
||||
if (!globals->get_scenery()->get_cart_ground_intersection(pos, dir, nearestHit))
|
||||
return naNil();
|
||||
|
||||
const SGGeod geodHit = SGGeod::fromCart(nearestHit);
|
||||
const SGGeod geodHit = SGGeod::fromCart(nearestHit);
|
||||
|
||||
// build a hash for returned intersection
|
||||
naRef intersection_h = naNewHash(c);
|
||||
hashset(c, intersection_h, "lat", naNum(geodHit.getLatitudeDeg()));
|
||||
hashset(c, intersection_h, "lon", naNum(geodHit.getLongitudeDeg()));
|
||||
hashset(c, intersection_h, "elevation", naNum(geodHit.getElevationM()));
|
||||
return intersection_h;
|
||||
// build a hash for returned intersection
|
||||
naRef intersection_h = naNewHash(c);
|
||||
hashset(c, intersection_h, "lat", naNum(geodHit.getLatitudeDeg()));
|
||||
hashset(c, intersection_h, "lon", naNum(geodHit.getLongitudeDeg()));
|
||||
hashset(c, intersection_h, "elevation", naNum(geodHit.getElevationM()));
|
||||
return intersection_h;
|
||||
}
|
||||
|
||||
// convert from aircraft reference frame to global (ECEF) cartesian
|
||||
|
|
|
@ -24,6 +24,13 @@ void FlightplanTests::setUp()
|
|||
{
|
||||
FGTestApi::setUp::initTestGlobals("flightplan");
|
||||
FGTestApi::setUp::initNavDataCache();
|
||||
|
||||
globals->get_subsystem_mgr()->init();
|
||||
|
||||
FGTestApi::setUp::initStandardNasal();
|
||||
|
||||
globals->get_subsystem_mgr()->postinit();
|
||||
globals->get_subsystem_mgr()->bind();
|
||||
}
|
||||
|
||||
|
||||
|
@ -320,3 +327,16 @@ void FlightplanTests::testBug1814()
|
|||
CPPUNIT_ASSERT_DOUBLES_EQUAL(137, leg->distanceNm(), 0.5);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(101, f->legAtIndex(2)->distanceNm(), 0.5);
|
||||
}
|
||||
|
||||
void FlightplanTests::testSegfaultWaypointGhost() {
|
||||
// checking for a segfault here, no segfault indicates success. A runtime error in the log is acceptable here.
|
||||
bool ok = FGTestApi::executeNasal(R"(
|
||||
var fp = createFlightplan();
|
||||
fp.departure = airportinfo("BIKF");
|
||||
fp.destination = airportinfo("EGLL");
|
||||
var wp = fp.getWP(1);
|
||||
fp.deleteWP(1);
|
||||
print(wp.wp_name);
|
||||
)");
|
||||
CPPUNIT_ASSERT(ok);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class FlightplanTests : public CppUnit::TestFixture
|
|||
CPPUNIT_TEST(testBasicAirways);
|
||||
CPPUNIT_TEST(testAirwayNetworkRoute);
|
||||
CPPUNIT_TEST(testBug1814);
|
||||
CPPUNIT_TEST(testSegfaultWaypointGhost);
|
||||
CPPUNIT_TEST(testRoutPathWpt0Midflight);
|
||||
CPPUNIT_TEST(testRoutePathVec);
|
||||
|
||||
|
@ -62,6 +63,7 @@ public:
|
|||
void testParseICAORoute();
|
||||
void testParseICANLowLevelRoute();
|
||||
void testBug1814();
|
||||
void testSegfaultWaypointGhost();
|
||||
void testRoutPathWpt0Midflight();
|
||||
void testRoutePathVec();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue