1
0
Fork 0

Fix crash in flight-plan UI

Sentry-Id: FLIGHTGEAR-ES
This commit is contained in:
James Turner 2020-10-23 15:40:16 +01:00
parent 3b01aaf33f
commit 4bbff581f3
2 changed files with 20 additions and 1 deletions

View file

@ -48,6 +48,8 @@ void RouteDiagram::setFlightplan(FlightPlanController *fp)
} }
m_flightplan = fp; m_flightplan = fp;
m_activeLegIndex = 0;
emit flightplanChanged(fp); emit flightplanChanged(fp);
if (fp) { if (fp) {
@ -76,6 +78,11 @@ void RouteDiagram::setActiveLegIndex(int activeLegIndex)
if (m_activeLegIndex == activeLegIndex) if (m_activeLegIndex == activeLegIndex)
return; return;
if ((activeLegIndex < 0) || (activeLegIndex >= numLegs())) {
qWarning() << Q_FUNC_INFO << "invalid leg index" << activeLegIndex;
return;
}
m_activeLegIndex = activeLegIndex; m_activeLegIndex = activeLegIndex;
emit legIndexChanged(m_activeLegIndex); emit legIndexChanged(m_activeLegIndex);
@ -132,7 +139,9 @@ void RouteDiagram::fpChanged()
{ {
FlightPlanRef fp = m_flightplan->flightplan(); FlightPlanRef fp = m_flightplan->flightplan();
m_path.reset(new RoutePath(fp)); m_path.reset(new RoutePath(fp));
if (fp) { m_activeLegIndex = 0;
if (fp && (fp->numLegs() > 0)) {
const double halfLegDistance = m_path->distanceForIndex(m_activeLegIndex) * 0.5; const double halfLegDistance = m_path->distanceForIndex(m_activeLegIndex) * 0.5;
m_projectionCenter = m_path->positionForDistanceFrom(m_activeLegIndex, halfLegDistance); m_projectionCenter = m_path->positionForDistanceFrom(m_activeLegIndex, halfLegDistance);
} }

View file

@ -1153,6 +1153,11 @@ double RoutePath::distanceForVia(Via* via, int index) const
double RoutePath::trackForIndex(int index) const double RoutePath::trackForIndex(int index) const
{ {
const auto sz = static_cast<int>(d->waypoints.size());
if ((index < 0) || (index >= sz)) {
return 0.0;
}
if (d->waypoints[index].skipped) if (d->waypoints[index].skipped)
return trackForIndex(index - 1); return trackForIndex(index - 1);
@ -1165,6 +1170,11 @@ double RoutePath::trackForIndex(int index) const
double RoutePath::distanceForIndex(int index) const double RoutePath::distanceForIndex(int index) const
{ {
const auto sz = static_cast<int>(d->waypoints.size());
if ((index < 0) || (index >= sz)) {
return 0.0;
}
return d->waypoints[index].pathDistanceM; return d->waypoints[index].pathDistanceM;
} }