From fc3a8f6690809bdcf4ef4f4f89ca776ac7ae2217 Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Sat, 15 Feb 2014 12:21:05 +0100 Subject: Calls Thread.sleep(5) only when there is no current OpenGL context yet in JoglCanvasRenderer --- .../ardor3d/framework/jogl/JoglCanvasRenderer.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'ardor3d-jogl/src/main') diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java index a86e3bc..2e8cd44 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java @@ -82,25 +82,29 @@ public class JoglCanvasRenderer implements CanvasRenderer { @Override public void makeCurrentContext() throws Ardor3dException { int value = GLContext.CONTEXT_NOT_CURRENT; - int attempt = 0; - do { + for (int attempt = 0;;) { try { value = _context.makeCurrent(); } catch (final GLException gle) { gle.printStackTrace(); } finally { attempt++; + } + if (value == GLContext.CONTEXT_NOT_CURRENT) { if (attempt == MAX_CONTEXT_GRAB_ATTEMPTS) { // failed, throw exception throw new Ardor3dException("Failed to claim OpenGL context."); + } else { + try { + Thread.sleep(5); + } catch (final InterruptedException e1) { + e1.printStackTrace(); + } } + } else { + break; } - try { - Thread.sleep(5); - } catch (final InterruptedException e1) { - e1.printStackTrace(); - } - } while (value == GLContext.CONTEXT_NOT_CURRENT); + } if (ContextManager.getCurrentContext() != null) { if (value == GLContext.CONTEXT_CURRENT_NEW) { ContextManager.getCurrentContext().contextLost(); -- cgit v1.2.3