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,6 +531,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
public void updateFigure() {
log.debug("3D Figure Updated");
cachedBounds = null;
if (canvas != null) {
canvas.invoke(true, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable drawable) {
@ -539,6 +540,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
}
});
}
}
private void internalRepaint() {
super.repaint();
@ -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) {