From: James Turner Date: Sat, 19 Dec 2015 05:42:22 +0000 (-0800) Subject: Trying to bullet-proof the traffic code. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=865bb365ed2cc1b49a88424c8f117a25c8d2af0b;p=flightgear.git Trying to bullet-proof the traffic code. --- diff --git a/src/ATC/GroundController.cxx b/src/ATC/GroundController.cxx index 23bb001a3..d238b44c3 100644 --- a/src/ATC/GroundController.cxx +++ b/src/ATC/GroundController.cxx @@ -107,6 +107,11 @@ void FGGroundController::announcePosition(int id, double radius, int leg, FGAIAircraft * aircraft) { + if (!aircraft || !aircraft->getPerformance()) { + SG_LOG(SG_ATC, SG_ALERT, "announcePosition: missing aircraft performance"); + return; + } + TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 5a0705d9f..98d8ec113 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -57,7 +57,10 @@ FGTaxiSegment::FGTaxiSegment(FGTaxiNode* aStart, FGTaxiNode* aEnd) : index(0), oppositeDirection(0) { -}; + if (!aStart || !aEnd) { + throw sg_exception("Missing node arguments creating FGTaxiSegment"); + } +} SGGeod FGTaxiSegment::getCenter() const { diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 7e8cdbdfc..691a34ea6 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -505,17 +505,53 @@ bool FGAISchedule::next() return true; } -time_t FGAISchedule::getDepartureTime() { return (*flights.begin())->getDepartureTime (); } +time_t FGAISchedule::getDepartureTime() +{ + if (flights.empty()) + return 0; + + return (*flights.begin())->getDepartureTime (); +} + +FGAirport *FGAISchedule::getDepartureAirport() +{ + if (flights.empty()) + return 0; + + return (*flights.begin())->getDepartureAirport(); +} + +FGAirport *FGAISchedule::getArrivalAirport() +{ + if (flights.empty()) + return 0; -FGAirport *FGAISchedule::getDepartureAirport() { return (*flights.begin())->getDepartureAirport(); } + return (*flights.begin())->getArrivalAirport (); +} -FGAirport *FGAISchedule::getArrivalAirport() { return (*flights.begin())->getArrivalAirport (); } +int FGAISchedule::getCruiseAlt() +{ + if (flights.empty()) + return 0; -int FGAISchedule::getCruiseAlt() { return (*flights.begin())->getCruiseAlt (); } + return (*flights.begin())->getCruiseAlt (); +} -const std::string &FGAISchedule::getCallSign() { return (*flights.begin())->getCallSign (); } +std::string FGAISchedule::getCallSign() +{ + if (flights.empty()) + return std::string(); -const std::string &FGAISchedule::getFlightRules() { return (*flights.begin())->getFlightRules (); } + return (*flights.begin())->getCallSign (); +} + +std::string FGAISchedule::getFlightRules() +{ + if (flights.empty()) + return std::string(); + + return (*flights.begin())->getFlightRules (); +} FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDestination, const string &req, diff --git a/src/Traffic/Schedule.hxx b/src/Traffic/Schedule.hxx index 12169f4b7..5d7a360c1 100644 --- a/src/Traffic/Schedule.hxx +++ b/src/Traffic/Schedule.hxx @@ -118,9 +118,9 @@ class FGAISchedule const std::string& getFlightType () { return flightType;}; const std::string& getAirline () { return airline; }; const std::string& getAircraft () { return acType; }; - const std::string& getCallSign (); + std::string getCallSign (); const std::string& getRegistration () { return registration;}; - const std::string& getFlightRules (); + std::string getFlightRules (); bool getHeavy () { return heavy; }; double getCourse () { return courseToDest; }; unsigned int getRunCount () { return runCount; };