From da84904133c2375c00c4290e8731f67f681f30a2 Mon Sep 17 00:00:00 2001
From: Kenneth Russel <kbrussel@alum.mit.edu>
Date: Wed, 17 Jan 2007 18:23:39 +0000
Subject: Fixed Issue 260: "GLException: Surface already locked" after failed
 makeCurrent

Added checking for thrown run-time exceptions to on-screen GLContext
makeCurrent() implementations on all three major supported platforms;
now unlocks the underlying GLDrawable if an exception is thrown.


git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1088 232f8b59-042b-4e1e-8c03-345bb8c30851
---
 .../com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java   | 11 +++++++----
 .../com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java | 11 +++++++----
 src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java | 11 +++++++----
 3 files changed, 21 insertions(+), 12 deletions(-)

(limited to 'src/classes/com/sun/opengl/impl')

diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java
index 9486f7c7b..5d8e91231 100644
--- a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java
+++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java
@@ -55,6 +55,7 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
 
   protected int makeCurrentImpl() throws GLException {
     int lockRes = drawable.lockSurface();
+    boolean exceptionOccurred = false;
     try {
       if (lockRes == MacOSXOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
         return CONTEXT_NOT_CURRENT;
@@ -81,11 +82,13 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
         }
       }
       return ret;
+    } catch (RuntimeException e) {
+      exceptionOccurred = true;
+      throw e;
     } finally {
-      if (isOptimizable()) {
-        if (lockRes != MacOSXOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
-          drawable.unlockSurface();
-        }
+      if (exceptionOccurred ||
+          (isOptimizable() && lockRes != MacOSXOnscreenGLDrawable.LOCK_SURFACE_NOT_READY)) {
+        drawable.unlockSurface();
       }
     }
   }
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java
index e6a0d432f..066cb8fa6 100644
--- a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java
@@ -55,6 +55,7 @@ public class WindowsOnscreenGLContext extends WindowsGLContext {
   
   protected int makeCurrentImpl() throws GLException {
     int lockRes = drawable.lockSurface();
+    boolean exceptionOccurred = false;
     try {
       if (lockRes == WindowsOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
         return CONTEXT_NOT_CURRENT;
@@ -64,11 +65,13 @@ public class WindowsOnscreenGLContext extends WindowsGLContext {
       }
       int ret = super.makeCurrentImpl();
       return ret;
+    } catch (RuntimeException e) {
+      exceptionOccurred = true;
+      throw e;
     } finally {
-      if (isOptimizable()) {
-        if (lockRes != WindowsOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
-          drawable.unlockSurface();
-        }
+      if (exceptionOccurred ||
+          (isOptimizable() && lockRes != WindowsOnscreenGLDrawable.LOCK_SURFACE_NOT_READY)) {
+        drawable.unlockSurface();
       }
     }
   }
diff --git a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java
index 908257ba1..bab780219 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java
@@ -59,6 +59,7 @@ public class X11OnscreenGLContext extends X11GLContext {
   
   protected int makeCurrentImpl() throws GLException {
     int lockRes = drawable.lockSurface();
+    boolean exceptionOccurred = false;
     try {
       if (lockRes == X11OnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
         return CONTEXT_NOT_CURRENT;
@@ -67,11 +68,13 @@ public class X11OnscreenGLContext extends X11GLContext {
         destroyImpl();
       }
       return super.makeCurrentImpl();
+    } catch (RuntimeException e) {
+      exceptionOccurred = true;
+      throw e;
     } finally {
-      if (isOptimizable()) {
-        if (lockRes != X11OnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
-          drawable.unlockSurface();
-        }
+      if (exceptionOccurred ||
+          (isOptimizable() && lockRes != X11OnscreenGLDrawable.LOCK_SURFACE_NOT_READY)) {
+        drawable.unlockSurface();
       }
     }
   }
-- 
cgit v1.2.3