From 894ac897337ef6d1989054c1bda6761707430ed5 Mon Sep 17 00:00:00 2001 From: Sibo Van Gool Date: Thu, 26 Aug 2021 11:46:35 +0200 Subject: [PATCH] [fixes #927] Q&D fix for NullPointerException upon no motors sim run --- .../atmosphere/InterpolatingAtmosphericModel.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/models/atmosphere/InterpolatingAtmosphericModel.java b/core/src/net/sf/openrocket/models/atmosphere/InterpolatingAtmosphericModel.java index 6b383b513..780adc300 100644 --- a/core/src/net/sf/openrocket/models/atmosphere/InterpolatingAtmosphericModel.java +++ b/core/src/net/sf/openrocket/models/atmosphere/InterpolatingAtmosphericModel.java @@ -18,10 +18,20 @@ public abstract class InterpolatingAtmosphericModel implements AtmosphericModel if (levels == null) computeLayers(); - if (altitude <= 0) + if (altitude <= 0) { + // TODO: LOW: levels[0] returned null in some cases, see GitHub issue #952 for more information + if (levels[0] == null) { + computeLayers(); + } return levels[0]; - if (altitude >= DELTA * (levels.length - 1)) + } + if (altitude >= DELTA * (levels.length - 1)) { + // TODO: LOW: levels[levels.length - 1] returned null in some cases, see GitHub issue #952 for more information + if (levels[levels.length - 1] == null) { + computeLayers(); + } return levels[levels.length - 1]; + } int n = (int) (altitude / DELTA); double d = (altitude - n * DELTA) / DELTA;