From 880c498e4b360fa2f51feb606e621badf902ab83 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sat, 12 Feb 2005 19:45:46 +0000 Subject: Fixed Issue 110: NativeLibLoader should have a flag for loading the library Applied suggested patch from submitter. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@225 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/net/java/games/jogl/impl/NativeLibLoader.java | 61 +++++++++++++---------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/net/java/games/jogl/impl/NativeLibLoader.java b/src/net/java/games/jogl/impl/NativeLibLoader.java index cf2b06939..0c2420955 100644 --- a/src/net/java/games/jogl/impl/NativeLibLoader.java +++ b/src/net/java/games/jogl/impl/NativeLibLoader.java @@ -42,34 +42,45 @@ package net.java.games.jogl.impl; import java.security.*; public class NativeLibLoader { - static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - boolean isOSX = System.getProperty("os.name").equals("Mac OS X"); - if (!isOSX) { - try { - System.loadLibrary("jawt"); - } catch (UnsatisfiedLinkError e) { - // Accessibility technologies load JAWT themselves; safe to continue - // as long as JAWT is loaded by any loader - if (e.getMessage().indexOf("already loaded") == -1) { - throw e; - } - } - } - System.loadLibrary("jogl"); + private static volatile boolean doLoading = true; + private static volatile boolean doneLoading = false; - // Workaround for 4845371. - // Make sure the first reference to the JNI GetDirectBufferAddress is done - // from a privileged context so the VM's internal class lookups will succeed. - JAWT jawt = new JAWT(); - JAWTFactory.JAWT_GetAWT(jawt); + public static void disableLoading() { + doLoading = false; + } - return null; - } - }); + public static void enableLoading() { + doLoading = true; } - public static void load() { + public static synchronized void load() { + if (doLoading && !doneLoading) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + boolean isOSX = System.getProperty("os.name").equals("Mac OS X"); + if (!isOSX) { + try { + System.loadLibrary("jawt"); + } catch (UnsatisfiedLinkError e) { + // Accessibility technologies load JAWT themselves; safe to continue + // as long as JAWT is loaded by any loader + if (e.getMessage().indexOf("already loaded") == -1) { + throw e; + } + } + } + System.loadLibrary("jogl"); + + // Workaround for 4845371. + // Make sure the first reference to the JNI GetDirectBufferAddress is done + // from a privileged context so the VM's internal class lookups will succeed. + JAWT jawt = new JAWT(); + JAWTFactory.JAWT_GetAWT(jawt); + + return null; + } + }); + doneLoading = true; + } } } -- cgit v1.2.3