From 11c5e072f09fd3d5badcb9cd7153997904f45f8c Mon Sep 17 00:00:00 2001 From: bkuker Date: Mon, 2 Sep 2013 18:46:58 -0400 Subject: [PATCH] Fix for Issue #122, NPE in RocketFigure3d.setType() This problem will only happen when the RocketFigure3d is unable to create a GL canvas. It sets the canvas to null, but not all code that uses canvas checks for null. This class probably should handle this state better than it does, but this is the safe change now. --- .../gui/figure3d/RocketFigure3d.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 2c3d84fde..a1990d58f 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -531,13 +531,15 @@ public class RocketFigure3d extends JPanel implements GLEventListener { public void updateFigure() { log.debug("3D Figure Updated"); cachedBounds = null; - canvas.invoke(true, new GLRunnable() { - @Override - public boolean run(GLAutoDrawable drawable) { - rr.updateFigure(drawable); - return false; - } - }); + if (canvas != null) { + canvas.invoke(true, new GLRunnable() { + @Override + public boolean run(GLAutoDrawable drawable) { + rr.updateFigure(drawable); + return false; + } + }); + } } private void internalRepaint() { @@ -651,12 +653,17 @@ public class RocketFigure3d extends JPanel implements GLEventListener { } public void setType(final int t) { + //There is no canvas if there was an error while creating it. + if (canvas == null) + return; + // The first time the user selects any 3d figure types, the canvas' internal _drawable // has not been realized. Unfortunately, there is a test in canvas.invoke which doesn't // execute the runnable if the drawable isn't realized. // In order to trump this, we test if the canvas has not been realized and initialize // the renderer accordingly. There is certainly a better way to do this. + final RocketRenderer newRR; switch (t) {