diff options
author | Sven Gothel <[email protected]> | 2011-07-07 03:41:25 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-07-07 03:41:25 +0200 |
commit | 64af11278dfe4d3feb223775e0b3a83a968fcabc (patch) | |
tree | 2582ce5972a2fbd58b72ff48fb92ed9d33bec794 /src/jogl/classes/jogamp/opengl | |
parent | 29cc5fa0375026c09bcbfed16627fe9eb6c97846 (diff) |
Fix SharedResource (SR) Initialization
- Catch exceptions in SR thread avoiding deadlock in blocking caller thread
- Catch NPE on SR queries to return null if appropriate
Diffstat (limited to 'src/jogl/classes/jogamp/opengl')
3 files changed, 70 insertions, 64 deletions
diff --git a/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java b/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java index 386679992..2c396e265 100644 --- a/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java +++ b/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java @@ -83,43 +83,40 @@ public class SharedResourceRunner implements Runnable { this.impl = impl; } - public SharedResourceRunner.Resource getShared(AbstractGraphicsDevice device) { - String connection = device.getConnection(); - return impl.mapGet(connection); - } - public SharedResourceRunner.Resource getOrCreateShared(AbstractGraphicsDevice device) { - String connection = device.getConnection(); - SharedResourceRunner.Resource sr = impl.mapGet(connection); - - if (null == sr && !getDeviceTried(connection)) { - addDeviceTried(connection); - if (DEBUG) { - System.err.println("getOrCreateShared() " + connection + ": trying"); - } - doAndWait(connection, null); + SharedResourceRunner.Resource sr = null; + if(null != device) { + String connection = device.getConnection(); sr = impl.mapGet(connection); - if (DEBUG) { - Throwable t = new Throwable("getOrCreateSharedl() " + connection + ": done"); - t.printStackTrace(); + if (null == sr && !getDeviceTried(connection)) { + addDeviceTried(connection); + if (DEBUG) { + System.err.println("getOrCreateShared() " + connection + ": trying"); + } + doAndWait(connection, null); + sr = impl.mapGet(connection); + if (DEBUG) { + System.err.println("getOrCreateShared() " + connection + ": "+ ( ( null != sr ) ? "success" : "failed" ) ); + } } } return sr; } public SharedResourceRunner.Resource releaseShared(AbstractGraphicsDevice device) { - String connection = device.getConnection(); - SharedResourceRunner.Resource sr = impl.mapGet(connection); - - if (null != sr) { - removeDeviceTried(connection); - if (DEBUG) { - System.err.println("releaseShared() " + connection + ": trying"); - } - doAndWait(null, connection); - if (DEBUG) { - Throwable t = new Throwable("releaseSharedl() " + connection + ": done"); - t.printStackTrace(); + SharedResourceRunner.Resource sr = null; + if(null != device) { + String connection = device.getConnection(); + sr = impl.mapGet(connection); + if (null != sr) { + removeDeviceTried(connection); + if (DEBUG) { + System.err.println("releaseShared() " + connection + ": trying"); + } + doAndWait(null, connection); + if (DEBUG) { + System.err.println("releaseShared() " + connection + ": done"); + } } } return sr; @@ -203,7 +200,12 @@ public class SharedResourceRunner implements Runnable { if (DEBUG) { System.err.println(threadName + " create Shared for: " + initConnection); } - Resource sr = impl.createSharedResource(initConnection); + Resource sr = null; + try { + sr = impl.createSharedResource(initConnection); + } catch (Exception e) { + e.printStackTrace(); + } if (null != sr) { impl.mapPut(initConnection, sr); } @@ -212,10 +214,15 @@ public class SharedResourceRunner implements Runnable { if (DEBUG) { System.err.println(threadName + " release Shared for: " + releaseConnection); } - Resource sr = impl.mapPut(releaseConnection, null); + Resource sr = impl.mapGet(releaseConnection); if (null != sr) { - impl.releaseSharedResource(sr); - } + try { + impl.releaseSharedResource(sr); + impl.mapPut(releaseConnection, null); + } catch (Exception e) { + e.printStackTrace(); + } + } } } initConnection = null; diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index c9cdcad90..8b159ac8e 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -373,18 +373,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { final static String WGL_ARB_make_current_read = "WGL_ARB_make_current_read"; final static String wglMakeContextCurrent = "wglMakeContextCurrent"; - protected final GLContext getSharedContextImpl(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getShared(device); - if(null!=sr) { - return sr.getContext(); - } - return null; - } - - protected final boolean hasSharedContextImpl(AbstractGraphicsDevice device) { - return null != getSharedContextImpl(device); - } - protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); if(null!=sr) { diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index 8d9de8144..48f9dd875 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -289,27 +289,36 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } public final String getGLXVendorName(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).getGLXVendorName(); + if(null != device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).getGLXVendorName(); + } + return GLXUtil.getVendorName(device.getHandle()); } - return GLXUtil.getVendorName(device.getHandle()); + return null; } public final boolean isGLXVendorATI(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).isGLXVendorATI(); + if(null != device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).isGLXVendorATI(); + } + return GLXUtil.isVendorATI(device.getHandle()); } - return GLXUtil.isVendorATI(device.getHandle()); + return false; } public final boolean isGLXVendorNVIDIA(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return ((SharedResource)sr).isGLXVendorNVIDIA(); + if(null != device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).isGLXVendorNVIDIA(); + } + return GLXUtil.isVendorNVIDIA(device.getHandle()); } - return GLXUtil.isVendorNVIDIA(device.getHandle()); + return false; } protected final void shutdownInstance() { @@ -366,13 +375,15 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } public final boolean isGLXVersionGreaterEqualOneThree(AbstractGraphicsDevice device) { - SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return sr.isGLXVersionGreaterEqualOneThree(); - } - if( device instanceof X11GraphicsDevice ) { - VersionNumber v = getGLXVersion( (X11GraphicsDevice) device); - return ( null != v ) ? v.compareTo(versionOneThree) >= 0 : false ; + if(null != device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.isGLXVersionGreaterEqualOneThree(); + } + if( device instanceof X11GraphicsDevice ) { + VersionNumber v = getGLXVersion( (X11GraphicsDevice) device); + return ( null != v ) ? v.compareTo(versionOneThree) >= 0 : false ; + } } return false; } |