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.
This commit is contained in:
bkuker 2013-09-02 18:46:58 -04:00
parent 0bc139fd05
commit 11c5e072f0

View File

@ -531,13 +531,15 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
public void updateFigure() { public void updateFigure() {
log.debug("3D Figure Updated"); log.debug("3D Figure Updated");
cachedBounds = null; cachedBounds = null;
canvas.invoke(true, new GLRunnable() { if (canvas != null) {
@Override canvas.invoke(true, new GLRunnable() {
public boolean run(GLAutoDrawable drawable) { @Override
rr.updateFigure(drawable); public boolean run(GLAutoDrawable drawable) {
return false; rr.updateFigure(drawable);
} return false;
}); }
});
}
} }
private void internalRepaint() { private void internalRepaint() {
@ -651,12 +653,17 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
} }
public void setType(final int t) { 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 // 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 // has not been realized. Unfortunately, there is a test in canvas.invoke which doesn't
// execute the runnable if the drawable isn't realized. // 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 // 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. // the renderer accordingly. There is certainly a better way to do this.
final RocketRenderer newRR; final RocketRenderer newRR;
switch (t) { switch (t) {