From 22ee569d3207e644db1c8c4376b4dd248df9c9a2 Mon Sep 17 00:00:00 2001 From: Bill Kuker Date: Thu, 27 Sep 2012 16:23:00 +0000 Subject: [PATCH] Add a timed check for GL Crash. Really a last resort. --- .../openrocket/gui/figure3d/OpenGLUtils.java | 36 +++++++++++++++++-- .../gui/figure3d/RocketFigure3d.java | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/figure3d/OpenGLUtils.java b/core/src/net/sf/openrocket/gui/figure3d/OpenGLUtils.java index e82b91dbc..c5ad8d4de 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/OpenGLUtils.java +++ b/core/src/net/sf/openrocket/gui/figure3d/OpenGLUtils.java @@ -76,7 +76,7 @@ public class OpenGLUtils { * exitDangerZone is not called after this the 3D user preference will be * disabled at the next startup. */ - static void enterDangerZone(String where) { + static void enterDangerZone(final String where) { log.verbose("Entering GL DangerZone: " + where); inTheDangerZone = true; Application.getPreferences().set3dEnabled(false); @@ -93,7 +93,7 @@ public class OpenGLUtils { * * Safe to call when not in the danger-zone. Safe to call quite often */ - static void exitDangerZone(String where) { + static void exitDangerZone(final String where) { if (!inTheDangerZone) return; inTheDangerZone = false; @@ -106,6 +106,38 @@ public class OpenGLUtils { } } + /** + * Enter a DangerZone for a set amount of time. If the app crashes before + * expiration, disable 3D. + * + * @param where + * @param milliseconds + */ + static void timedDangerZone(final String where, final long milliseconds){ + enterDangerZone(where + " - timed"); + final Thread onShutdown = new Thread(){ + @Override + public void run(){ + exitDangerZone(where + " - shutdown hook"); + } + }; + Runtime.getRuntime().addShutdownHook(onShutdown); + new Thread(){ + @Override + public void run(){ + try { + Thread.sleep(milliseconds); + } catch (InterruptedException e) { + log.warn("timedDangerZone sleep interrupted."); + } finally { + exitDangerZone(where + " - time expired"); + Runtime.getRuntime().removeShutdownHook(onShutdown); + } + } + }.start(); + + } + /** * Seriously never call this it will segfault the JVM. @Deprecated diff --git a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java index 990f966e2..5175325f0 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java +++ b/core/src/net/sf/openrocket/gui/figure3d/RocketFigure3d.java @@ -176,6 +176,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener { } finally { OpenGLUtils.exitDangerZone("initGLCanvas"); } + OpenGLUtils.timedDangerZone("after initGLCanvas", 5000); } /**