fix: load OpenAL based on java.library.path
This commit is contained in:
parent
0cf93ebe93
commit
dd201b2f14
|
@ -31,6 +31,9 @@
|
|||
*/
|
||||
package org.lwjgl.openal;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
|
@ -71,10 +74,34 @@ public abstract class BaseAL {
|
|||
*/
|
||||
public void create() throws Exception {
|
||||
if (created) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!nCreate()) {
|
||||
|
||||
// need to pass path of possible locations of OAL to native side
|
||||
String libpath = System.getProperty("java.library.path");
|
||||
String seperator = System.getProperty("path.separator");
|
||||
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";
|
||||
|
||||
StringTokenizer st = new StringTokenizer(libpath, seperator);
|
||||
|
||||
//create needed string array
|
||||
String[] oalPaths = new String[st.countTokens()+1];
|
||||
|
||||
//build paths
|
||||
for(int i=0;i<st.countTokens();i++) {
|
||||
oalPaths[i] = st.nextToken() + File.separator + libname;
|
||||
}
|
||||
|
||||
//add cwd path
|
||||
oalPaths[oalPaths.length-1] = libname;
|
||||
|
||||
if (!nCreate(oalPaths)) {
|
||||
throw new Exception("AL instance could not be created.");
|
||||
}
|
||||
created = true;
|
||||
|
@ -86,7 +113,7 @@ public abstract class BaseAL {
|
|||
*
|
||||
* @return true if the AL creation process succeeded
|
||||
*/
|
||||
protected native boolean nCreate();
|
||||
protected native boolean nCreate(String[] oalPaths);
|
||||
|
||||
/**
|
||||
* Calls whatever destruction rutines that are needed
|
||||
|
|
|
@ -163,26 +163,35 @@ void* GetFunctionPointer(const char* function) {
|
|||
/**
|
||||
* Loads the OpenAL Library
|
||||
*/
|
||||
void LoadOpenAL(JNIEnv *env) {
|
||||
void LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
||||
jsize pathcount = env->GetArrayLength(oalPaths);
|
||||
#ifdef _DEBUG
|
||||
printf("Found %d OpenAL paths\n", pathcount);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
jstring propertykey;
|
||||
jstring librarypath;
|
||||
jclass systemclass;
|
||||
jmethodID propertymethod;
|
||||
//compile bitch!
|
||||
//propertykey = env->NewStringUTF("java.library.path");
|
||||
///*systemclass = */env->FindClass("java/lang/System");
|
||||
//propertymethod = env->GetStaticMethodID(systemclass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String");
|
||||
//librarypath = env->CallStaticObjectMethod(systemclass, jmethodID, propertykey);
|
||||
printf("Loaded library path: %s", librarypath);
|
||||
|
||||
//parse string
|
||||
|
||||
//try to load for each path
|
||||
handleOAL = LoadLibrary("OpenAL32.dll");
|
||||
for(int i=0;i<pathcount;i++) {
|
||||
jstring path = (jstring) env->GetObjectArrayElement(oalPaths, i);
|
||||
#ifdef _DEBUG
|
||||
printf("Testing '%s'\n", env->GetStringUTFChars(path, NULL));
|
||||
#endif
|
||||
handleOAL = LoadLibrary(env->GetStringUTFChars(path, NULL));
|
||||
if (handleOAL != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Found OpenAL at '%s'\n", env->GetStringUTFChars(path, NULL));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef _X11
|
||||
handleOAL = dlopen("libopenal.so", RTLD_LAZY);
|
||||
//handleOAL = dlopen("libopenal.so", RTLD_LAZY);
|
||||
for(int i=0;i<pathcount;i++) {
|
||||
jstring path = (jstring) env->GetObjectArrayElement(oalPaths, i);
|
||||
handleOAL = dlopen(env->GetStringUTFChars(path, NULL), RTLD_LAZY);
|
||||
if (handleOAL != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -201,13 +210,13 @@ void UnLoadOpenAL() {
|
|||
/**
|
||||
* Initializes OpenAL by loading the library
|
||||
*/
|
||||
int InitializeOpenAL(JNIEnv *env) {
|
||||
int InitializeOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
||||
if(handleOAL != 0) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
//load our library
|
||||
LoadOpenAL(env);
|
||||
LoadOpenAL(env, oalPaths);
|
||||
|
||||
// if we couldn't load the library, get out
|
||||
if(handleOAL == 0) {
|
||||
|
|
|
@ -135,7 +135,7 @@ DEFINE_GUID(DSPROPSETID_EAX20_BufferProperties,
|
|||
#define INITGUID
|
||||
#define OPENAL
|
||||
|
||||
int InitializeOpenAL(JNIEnv *env);
|
||||
int InitializeOpenAL(JNIEnv *env, jobjectArray oalPaths);
|
||||
void DeInitializeOpenAL();
|
||||
|
||||
//alc
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
* Method: nCreate
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_BaseAL_nCreate (JNIEnv *env, jobject obj) {
|
||||
if(!InitializeOpenAL(env)) {
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_BaseAL_nCreate (JNIEnv *env, jobject obj, jobjectArray oalPaths) {
|
||||
if(!InitializeOpenAL(env, oalPaths)) {
|
||||
jclass cls = env->FindClass("org/lwjgl/openal/OpenALException");
|
||||
env->ThrowNew(cls, "Unable to load function pointers to openal.");
|
||||
env->DeleteLocalRef(cls);
|
||||
|
|
|
@ -46,7 +46,7 @@ extern "C" {
|
|||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_BaseAL_nCreate
|
||||
(JNIEnv *, jobject);
|
||||
(JNIEnv *, jobject, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_openal_BaseAL
|
||||
|
|
Loading…
Reference in New Issue