Add a timed check for GL Crash. Really a last resort.

This commit is contained in:
Bill Kuker 2012-09-27 16:23:00 +00:00
parent b82be4fc02
commit 22ee569d32
2 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -176,6 +176,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
} finally {
OpenGLUtils.exitDangerZone("initGLCanvas");
}
OpenGLUtils.timedDangerZone("after initGLCanvas", 5000);
}
/**