Fix crash in flight-plan UI
Sentry-Id: FLIGHTGEAR-ES
This commit is contained in:
parent
3b01aaf33f
commit
4bbff581f3
2 changed files with 20 additions and 1 deletions
|
@ -48,6 +48,8 @@ void RouteDiagram::setFlightplan(FlightPlanController *fp)
|
|||
}
|
||||
|
||||
m_flightplan = fp;
|
||||
m_activeLegIndex = 0;
|
||||
|
||||
emit flightplanChanged(fp);
|
||||
|
||||
if (fp) {
|
||||
|
@ -76,6 +78,11 @@ void RouteDiagram::setActiveLegIndex(int activeLegIndex)
|
|||
if (m_activeLegIndex == activeLegIndex)
|
||||
return;
|
||||
|
||||
if ((activeLegIndex < 0) || (activeLegIndex >= numLegs())) {
|
||||
qWarning() << Q_FUNC_INFO << "invalid leg index" << activeLegIndex;
|
||||
return;
|
||||
}
|
||||
|
||||
m_activeLegIndex = activeLegIndex;
|
||||
emit legIndexChanged(m_activeLegIndex);
|
||||
|
||||
|
@ -132,7 +139,9 @@ void RouteDiagram::fpChanged()
|
|||
{
|
||||
FlightPlanRef fp = m_flightplan->flightplan();
|
||||
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;
|
||||
m_projectionCenter = m_path->positionForDistanceFrom(m_activeLegIndex, halfLegDistance);
|
||||
}
|
||||
|
|
|
@ -1153,6 +1153,11 @@ double RoutePath::distanceForVia(Via* via, 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)
|
||||
return trackForIndex(index - 1);
|
||||
|
||||
|
@ -1165,6 +1170,11 @@ double RoutePath::trackForIndex(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue