From fa6ee1d57d0771df018a890c9d6f62071deaeeac Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 8 Apr 2023 12:15:46 +0100 Subject: [PATCH] Protect against division by zero in level off calculation --- Nasal/FMGC/flightplan.nas | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index 733ab40a..19c92812 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -776,16 +776,19 @@ var flightPlanController = { calculateLvlOffPoint: func(deltaAltitude) { - me.distLvl = (deltaAltitude * pts.Velocities.groundspeedKt.getValue()) / (fmgc.Internal.vs.getValue() * 60); + me._verticalSpeedVal = fmgc.Internal.vs.getValue(); + if (me._verticalSpeedVal != 0) { + me.distLvl = (deltaAltitude * pts.Velocities.groundspeedKt.getValue()) / (fmgc.Internal.vs.getValue() * 60); + } else { + me.distLvl = 999; + } if (me.active.getBoolValue() and fmgc.Output.lat.getValue() == 1 and me.distLvl >= 0) { # NAV me.lvlOffPoint = me.flightplans[2].pathGeod(me.currentToWptIndex.getValue() - 1, me.flightplans[2].getWP(me.currentToWptIndex.getValue()).leg_distance - me.distToWpt.getValue() + me.distLvl); } elsif (fmgc.Output.lat.getValue() == 0 and me.distLvl >= 0) { # HDG TRK - var coord = geo.aircraft_position(); - coord.apply_course_distance(getprop("/orientation/track-magnetic-deg"), me.distLvl * NM2M); - var latGeo = coord.lat(); - var lonGeo = coord.lon(); - me.lvlOffPoint = {lat: latGeo, lon: lonGeo}; + me._lvlOffCoord = geo.aircraft_position(); + me._lvlOffCoord.apply_course_distance(getprop("/orientation/track-magnetic-deg"), me.distLvl * NM2M); + me.lvlOffPoint = {lat: me._lvlOffCoord.lat(), lon: me._lvlOffCoord.lon()}; } else { setprop("/autopilot/route-manager/vnav/ec/show", 0); setprop("/autopilot/route-manager/vnav/ed/show", 0);