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.miginfocom.swing.MigLayout;
import net.sf.openrocket.database.ThrustCurveMotorSetDatabase; import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.logging.LogHelper;
@ -61,7 +62,8 @@ public class MotorDatabaseLoadingDialog extends JDialog {
if (db.isLoaded()) if (db.isLoaded())
return; return;
if (SplashScreen.getSplashScreen() == null) { SplashScreen splash = Splash.getSplashScreen();
if (splash == null || !splash.isVisible()) {
log.info(1, "Motor database not loaded yet, displaying dialog"); 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.CGCaret;
import net.sf.openrocket.gui.figureelements.CPCaret; import net.sf.openrocket.gui.figureelements.CPCaret;
import net.sf.openrocket.gui.figureelements.FigureElement; import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.Configuration; import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -89,8 +90,8 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
//Only initizlize GL if 3d is enabled. //Only initizlize GL if 3d is enabled.
if (is3dEnabled()) { if (is3dEnabled()) {
//Fixes a linux / X bug: Splash must be closed before GL Init //Fixes a linux / X bug: Splash must be closed before GL Init
SplashScreen splash = SplashScreen.getSplashScreen(); SplashScreen splash = Splash.getSplashScreen();
if ( splash != null ) if (splash != null && splash.isVisible())
splash.close(); splash.close();
initGLCanvas(); initGLCanvas();
@ -223,12 +224,12 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
if (pressEvent.getButton() == MouseEvent.BUTTON1) { if (pressEvent.getButton() == MouseEvent.BUTTON1) {
if (Math.abs(dx) > Math.abs(dy)) { if (Math.abs(dx) > Math.abs(dy)) {
setYaw(yaw - (float) dx / 100.0); setYaw(yaw - dx / 100.0);
} else { } 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; dy = -dy;
} }
setRoll(roll - (float) dy / 100.0); setRoll(roll - dy / 100.0);
} }
} else { } else {
lightPosition[0] -= 0.1f * dx; lightPosition[0] -= 0.1f * dx;

View File

@ -38,7 +38,7 @@ public class Splash {
*/ */
public static boolean init() { public static boolean init() {
// Get the splash screen // Get the splash screen
SplashScreen s = getSplash(); SplashScreen s = getSplashScreen();
if (s == null) if (s == null)
return false; 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. * 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 { try {
return SplashScreen.getSplashScreen(); SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null && splash.isVisible()) {
return splash;
} else {
return null;
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
return null; return null;
} }