From ed0d58cd752d7f0ad5d31c138d9387c123ce3975 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 22 Apr 2012 15:19:20 +0200 Subject: [PATCH] #705: add sanity checks to fuel tank update Just ignore incomplete tanks (without essential properties like "level_lbs") and avoid Nasal run-time errors. --- Nasal/fuel.nas | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Nasal/fuel.nas b/Nasal/fuel.nas index d7054afbd..c24899e4f 100644 --- a/Nasal/fuel.nas +++ b/Nasal/fuel.nas @@ -28,11 +28,13 @@ var update = func { var selected_tanks = []; foreach (var t; tanks) { var cap = t.getNode("capacity-gal_us",0); - if ((cap!=nil) and (cap.getValue() > 0.01) and t.getNode("selected").getBoolValue()) + var selected = t.getNode("selected"); + if ((cap!=nil) and (cap.getValue() > 0.01) and (t.getNode("level-lbs") != nil) and + (selected != nil) and selected.getBoolValue()) append(selected_tanks, t); } - # Subtract fuel from tanks, set auxilliary properties. Set out-of-fuel + # Subtract fuel from tanks, set auxiliary properties. Set out-of-fuel # when any one tank is dry. var out_of_fuel = 0; if (size(selected_tanks) == 0) { @@ -40,10 +42,14 @@ var update = func { } else { var fuel_per_tank = consumed_fuel / size(selected_tanks); foreach (var t; selected_tanks) { - var lbs = t.getNode("level-lbs").getValue(); - lbs = lbs - fuel_per_tank; - t.getNode("level-lbs").setDoubleValue(lbs); - if( t.getNode("empty").getBoolValue() ) { + var lbs = t.getNode("level-lbs"); + lbs.setDoubleValue(lbs.getValue() - fuel_per_tank); + var empty = t.getNode("empty"); + if (empty == nil) + empty = (lbs.getValue() <= 0); + else + empty = empty.getBoolValue(); + if( empty ) { # Kill the engines if we're told to, otherwise simply # deselect the tank. if (t.getNode("kill-when-empty", 1).getBoolValue())