Fixes #1319 - LWJGL2: start(true) should not freeze when context could not be initialized

v3.3
MeFisto94 5 years ago committed by Stephen Gold
parent 828ca9212a
commit 7e3ae5e8ca
  1. 14
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java

@ -90,14 +90,14 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
/** /**
* Does LWJGL display initialization in the OpenGL thread * Does LWJGL display initialization in the OpenGL thread
*/ */
protected boolean initInThread(){ protected boolean initInThread() {
try { try {
if (!JmeSystem.isLowPermissions()){ if (!JmeSystem.isLowPermissions()) {
// Enable uncaught exception handler only for current thread // Enable uncaught exception handler only for current thread
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable thrown) { public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown); listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
if (needClose.get()){ if (needClose.get()) {
// listener.handleError() has requested the // listener.handleError() has requested the
// context to close. Satisfy request. // context to close. Satisfy request.
deinitInThread(); deinitInThread();
@ -115,15 +115,17 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
created.set(true); created.set(true);
super.internalCreate(); super.internalCreate();
} catch (Exception ex){ } catch (Exception ex) {
try { try {
if (Display.isCreated()) if (Display.isCreated()) {
Display.destroy(); Display.destroy();
}
} catch (Exception ex2){ } catch (Exception ex2){
logger.log(Level.WARNING, null, ex2); logger.log(Level.WARNING, null, ex2);
} }
listener.handleError("Failed to create display", ex); listener.handleError("Failed to create display", ex);
createdLock.notifyAll(); // Release the lock, so start(true) doesn't deadlock.
return false; // if we failed to create display, do not continue return false; // if we failed to create display, do not continue
} }
@ -131,7 +133,7 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
return true; return true;
} }
protected boolean checkGLError(){ protected boolean checkGLError() {
try { try {
Util.checkGLError(); Util.checkGLError();
} catch (OpenGLException ex){ } catch (OpenGLException ex){

Loading…
Cancel
Save