Fix crash at startup due to splash screen handling

This commit is contained in:
Sampo Niskanen 2012-09-26 14:51:28 +00:00
parent a28c99fc54
commit efb4952333
3 changed files with 113 additions and 105 deletions

View File

@ -13,6 +13,7 @@ import javax.swing.Timer;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
@ -61,7 +62,8 @@ public class MotorDatabaseLoadingDialog extends JDialog {
if (db.isLoaded())
return;
if (SplashScreen.getSplashScreen() == null) {
SplashScreen splash = Splash.getSplashScreen();
if (splash == null || !splash.isVisible()) {
log.info(1, "Motor database not loaded yet, displaying dialog");

View File

@ -34,6 +34,7 @@ import javax.swing.event.MouseInputAdapter;
import net.sf.openrocket.gui.figureelements.CGCaret;
import net.sf.openrocket.gui.figureelements.CPCaret;
import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -87,10 +88,10 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
this.setLayout(new BorderLayout());
//Only initizlize GL if 3d is enabled.
if ( is3dEnabled() ){
if (is3dEnabled()) {
//Fixes a linux / X bug: Splash must be closed before GL Init
SplashScreen splash = SplashScreen.getSplashScreen();
if ( splash != null )
SplashScreen splash = Splash.getSplashScreen();
if (splash != null && splash.isVisible())
splash.close();
initGLCanvas();
@ -102,11 +103,11 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
* launch time.
* @return
*/
public static boolean is3dEnabled(){
public static boolean is3dEnabled() {
return System.getProperty("openrocket.3d.disable") == null;
}
private void initGLCanvas(){
private void initGLCanvas() {
log.debug("Initializing RocketFigure3D OpenGL Canvas");
try {
log.debug("Setting up GL capabilities...");
@ -152,7 +153,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
/**
* Set up the standard rendering hints on the Graphics2D
*/
private static void setRenderingHints(Graphics2D g){
private static void setRenderingHints(Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
@ -165,7 +166,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
* Rasterize the carets into 2 buffered images that I can blit onto the
* 3d display every redraw without all of the caret shape rendering overhead
*/
private void rasterizeCarets(){
private void rasterizeCarets() {
Graphics2D g2d;
//Rasterize a CG Caret
@ -176,7 +177,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
g2d.setBackground(new Color(0, 0, 0, 0));
g2d.clearRect(0, 0, CARET_SIZE, CARET_SIZE);
new CGCaret(CARET_SIZE/2,CARET_SIZE/2).paint(g2d, 1.0);
new CGCaret(CARET_SIZE / 2, CARET_SIZE / 2).paint(g2d, 1.0);
g2d.dispose();
@ -188,7 +189,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
g2d.setBackground(new Color(0, 0, 0, 0));
g2d.clearRect(0, 0, CARET_SIZE, CARET_SIZE);
new CPCaret(CARET_SIZE/2,CARET_SIZE/2).paint(g2d, 1.0);
new CPCaret(CARET_SIZE / 2, CARET_SIZE / 2).paint(g2d, 1.0);
g2d.dispose();
@ -223,12 +224,12 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
if (pressEvent.getButton() == MouseEvent.BUTTON1) {
if (Math.abs(dx) > Math.abs(dy)) {
setYaw(yaw - (float) dx / 100.0);
setYaw(yaw - dx / 100.0);
} else {
if ( yaw > Math.PI/2.0 && yaw < 3.0*Math.PI/2.0 ){
if (yaw > Math.PI / 2.0 && yaw < 3.0 * Math.PI / 2.0) {
dy = -dy;
}
setRoll(roll - (float) dy / 100.0);
setRoll(roll - dy / 100.0);
}
} else {
lightPosition[0] -= 0.1f * dx;
@ -261,7 +262,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
if (pickPoint != null) {
gl.glDisable(GLLightingFunc.GL_LIGHTING);
final RocketComponent picked = rr.pick(drawable, configuration,
pickPoint, pickEvent.isShiftDown()?selection:null );
pickPoint, pickEvent.isShiftDown() ? selection : null);
if (csl != null && picked != null) {
final MouseEvent e = pickEvent;
SwingUtilities.invokeLater(new Runnable() {
@ -299,7 +300,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
Coordinate pCP = project(cp, gl, glu);
Coordinate pCG = project(cg, gl, glu);
final int d = CARET_SIZE/2;
final int d = CARET_SIZE / 2;
//z order the carets
if (pCG.z < pCP.z) {
@ -335,13 +336,13 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
* Re-blits the overlay every frame. Only re-renders the overlay
* when needed.
*/
private void drawExtras(GL2 gl, GLU glu){
private void drawExtras(GL2 gl, GLU glu) {
//Only re-render if needed
// redrawExtras: Some external change (new simulation data) means
// the data is out of date.
// extrasOverlay.contentsLost(): For some reason the buffer with this
// data is lost.
if ( redrawExtras || extrasOverlay.contentsLost() ){
if (redrawExtras || extrasOverlay.contentsLost()) {
log.debug("Redrawing Overlay");
final Graphics2D og2d = extrasOverlay.createGraphics();
@ -493,8 +494,8 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
//Flip textures for LEFT handed coords
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glLoadIdentity();
gl.glScaled(-1,1,1);
gl.glTranslated(-1,0,0);
gl.glScaled(-1, 1, 1);
gl.glTranslated(-1, 0, 0);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
log.verbose("GL - setupView() complete");
@ -509,7 +510,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
internalRepaint();
}
private void internalRepaint(){
private void internalRepaint() {
log.verbose("GL - internalRepaint() called");
super.repaint();
if (canvas != null)

View File

@ -38,7 +38,7 @@ public class Splash {
*/
public static boolean init() {
// Get the splash screen
SplashScreen s = getSplash();
SplashScreen s = getSplashScreen();
if (s == null)
return false;
@ -75,14 +75,19 @@ public class Splash {
/**
* Return the current splash screen or <code>null</code> if not available.
* Return the current splash screen or <code>null</code> if not available or already closed.
* This method catches the possible exceptions and returns null if they occur.
*
* @return the current splash screen, or <code>null</code>.
* @return the current (visible) splash screen, or <code>null</code>.
*/
private static SplashScreen getSplash() {
public static SplashScreen getSplashScreen() {
try {
return SplashScreen.getSplashScreen();
SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null && splash.isVisible()) {
return splash;
} else {
return null;
}
} catch (RuntimeException e) {
return null;
}