fix: Java Web Start loading of OpenAL
This commit is contained in:
parent
bf2ff00518
commit
3f54bac547
|
@ -33,6 +33,9 @@ package org.lwjgl.openal;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
|
@ -83,7 +86,17 @@ public abstract class BaseAL {
|
|||
String libname;
|
||||
|
||||
// libname is hardcoded atm - this will change in a near future...
|
||||
libname = (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) ? "libopenal.so" : "OpenAL32.dll";
|
||||
libname =
|
||||
(System.getProperty("os.name").toLowerCase().indexOf("windows") == -1)
|
||||
? "libopenal.so"
|
||||
: "OpenAL32.dll";
|
||||
|
||||
// try to get path from JWS (if possible)
|
||||
String jwsPath = getPathFromJWS(libname);
|
||||
if (jwsPath != null) {
|
||||
libpath += seperator
|
||||
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
|
||||
}
|
||||
|
||||
StringTokenizer st = new StringTokenizer(libpath, seperator);
|
||||
|
||||
|
@ -105,6 +118,40 @@ public abstract class BaseAL {
|
|||
created = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to locate OpenAL from the JWS Library path
|
||||
* This method exists because OpenAL is loaded from native code, and as such
|
||||
* is exempt from JWS library loading rutines. OpenAL therefore always fails.
|
||||
* We therefore invoke the protected method of the JWS classloader to see if it can
|
||||
* locate it.
|
||||
*
|
||||
* @param libname Name of library to search for
|
||||
* @return Absolute path to library if found, otherwise null
|
||||
*/
|
||||
private String getPathFromJWS(String libname) {
|
||||
try {
|
||||
libname = libname.substring(0, libname.lastIndexOf("."));
|
||||
|
||||
if(Sys.DEBUG) {
|
||||
System.out.println("JWS Classloader looking for: " + libname);
|
||||
}
|
||||
|
||||
Object o = BaseAL.class.getClassLoader();
|
||||
Class c = o.getClass();
|
||||
Method findLibrary =
|
||||
c.getMethod("findLibrary", new Class[] { String.class });
|
||||
Object[] arguments = new Object[] { libname };
|
||||
return (String) findLibrary.invoke(o, arguments);
|
||||
|
||||
} catch (Exception e) {
|
||||
if(Sys.DEBUG) {
|
||||
System.out.println("Failure locating OpenAL using classloader:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native method to create AL instance
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue