Fix crash at startup due to splash screen handling
This commit is contained in:
parent
a28c99fc54
commit
efb4952333
@ -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");
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -87,10 +88,10 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
this.setLayout(new BorderLayout());
|
this.setLayout(new BorderLayout());
|
||||||
|
|
||||||
//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();
|
||||||
@ -102,11 +103,11 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
* launch time.
|
* launch time.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean is3dEnabled(){
|
public static boolean is3dEnabled() {
|
||||||
return System.getProperty("openrocket.3d.disable") == null;
|
return System.getProperty("openrocket.3d.disable") == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initGLCanvas(){
|
private void initGLCanvas() {
|
||||||
log.debug("Initializing RocketFigure3D OpenGL Canvas");
|
log.debug("Initializing RocketFigure3D OpenGL Canvas");
|
||||||
try {
|
try {
|
||||||
log.debug("Setting up GL capabilities...");
|
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
|
* 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,
|
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
|
||||||
RenderingHints.VALUE_STROKE_NORMALIZE);
|
RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||||
g.setRenderingHint(RenderingHints.KEY_RENDERING,
|
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
|
* 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
|
* 3d display every redraw without all of the caret shape rendering overhead
|
||||||
*/
|
*/
|
||||||
private void rasterizeCarets(){
|
private void rasterizeCarets() {
|
||||||
Graphics2D g2d;
|
Graphics2D g2d;
|
||||||
|
|
||||||
//Rasterize a CG Caret
|
//Rasterize a CG Caret
|
||||||
@ -176,7 +177,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
g2d.setBackground(new Color(0, 0, 0, 0));
|
g2d.setBackground(new Color(0, 0, 0, 0));
|
||||||
g2d.clearRect(0, 0, CARET_SIZE, CARET_SIZE);
|
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();
|
g2d.dispose();
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
g2d.setBackground(new Color(0, 0, 0, 0));
|
g2d.setBackground(new Color(0, 0, 0, 0));
|
||||||
g2d.clearRect(0, 0, CARET_SIZE, CARET_SIZE);
|
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();
|
g2d.dispose();
|
||||||
|
|
||||||
@ -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;
|
||||||
@ -261,7 +262,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
if (pickPoint != null) {
|
if (pickPoint != null) {
|
||||||
gl.glDisable(GLLightingFunc.GL_LIGHTING);
|
gl.glDisable(GLLightingFunc.GL_LIGHTING);
|
||||||
final RocketComponent picked = rr.pick(drawable, configuration,
|
final RocketComponent picked = rr.pick(drawable, configuration,
|
||||||
pickPoint, pickEvent.isShiftDown()?selection:null );
|
pickPoint, pickEvent.isShiftDown() ? selection : null);
|
||||||
if (csl != null && picked != null) {
|
if (csl != null && picked != null) {
|
||||||
final MouseEvent e = pickEvent;
|
final MouseEvent e = pickEvent;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@ -299,7 +300,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
Coordinate pCP = project(cp, gl, glu);
|
Coordinate pCP = project(cp, gl, glu);
|
||||||
Coordinate pCG = project(cg, gl, glu);
|
Coordinate pCG = project(cg, gl, glu);
|
||||||
|
|
||||||
final int d = CARET_SIZE/2;
|
final int d = CARET_SIZE / 2;
|
||||||
|
|
||||||
//z order the carets
|
//z order the carets
|
||||||
if (pCG.z < pCP.z) {
|
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
|
* Re-blits the overlay every frame. Only re-renders the overlay
|
||||||
* when needed.
|
* when needed.
|
||||||
*/
|
*/
|
||||||
private void drawExtras(GL2 gl, GLU glu){
|
private void drawExtras(GL2 gl, GLU glu) {
|
||||||
//Only re-render if needed
|
//Only re-render if needed
|
||||||
// redrawExtras: Some external change (new simulation data) means
|
// redrawExtras: Some external change (new simulation data) means
|
||||||
// the data is out of date.
|
// the data is out of date.
|
||||||
// extrasOverlay.contentsLost(): For some reason the buffer with this
|
// extrasOverlay.contentsLost(): For some reason the buffer with this
|
||||||
// data is lost.
|
// data is lost.
|
||||||
if ( redrawExtras || extrasOverlay.contentsLost() ){
|
if (redrawExtras || extrasOverlay.contentsLost()) {
|
||||||
log.debug("Redrawing Overlay");
|
log.debug("Redrawing Overlay");
|
||||||
|
|
||||||
final Graphics2D og2d = extrasOverlay.createGraphics();
|
final Graphics2D og2d = extrasOverlay.createGraphics();
|
||||||
@ -493,8 +494,8 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
//Flip textures for LEFT handed coords
|
//Flip textures for LEFT handed coords
|
||||||
gl.glMatrixMode(GL.GL_TEXTURE);
|
gl.glMatrixMode(GL.GL_TEXTURE);
|
||||||
gl.glLoadIdentity();
|
gl.glLoadIdentity();
|
||||||
gl.glScaled(-1,1,1);
|
gl.glScaled(-1, 1, 1);
|
||||||
gl.glTranslated(-1,0,0);
|
gl.glTranslated(-1, 0, 0);
|
||||||
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
|
||||||
|
|
||||||
log.verbose("GL - setupView() complete");
|
log.verbose("GL - setupView() complete");
|
||||||
@ -509,7 +510,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
internalRepaint();
|
internalRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void internalRepaint(){
|
private void internalRepaint() {
|
||||||
log.verbose("GL - internalRepaint() called");
|
log.verbose("GL - internalRepaint() called");
|
||||||
super.repaint();
|
super.repaint();
|
||||||
if (canvas != null)
|
if (canvas != null)
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user