openal: Improved error reporting from native library load
This commit is contained in:
parent
c3500a14d2
commit
74ab4f7fa4
|
@ -162,7 +162,7 @@ void extal_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMet
|
|||
|
||||
/* Platform dependent functions */
|
||||
void *NativeGetFunctionPointer(const char *function);
|
||||
bool tryLoadLibrary(JNIEnv *env, jstring path);
|
||||
void tryLoadLibrary(JNIEnv *env, jstring path);
|
||||
void UnLoadOpenAL();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -35,9 +35,7 @@
|
|||
#include "extal.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nCreate(JNIEnv *env, jclass clazz, jstring oalPath) {
|
||||
if (!tryLoadLibrary(env, oalPath)) {
|
||||
throwException(env, "Could not load OpenAL library");
|
||||
}
|
||||
tryLoadLibrary(env, oalPath);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nDestroy(JNIEnv *env, jclass clazz) {
|
||||
|
|
|
@ -45,15 +45,16 @@ void *NativeGetFunctionPointer(const char *function) {
|
|||
return dlsym(handleOAL, function);
|
||||
}
|
||||
|
||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
char *path_str = GetStringNativeChars(env, path);
|
||||
printfDebugJava(env, "Testing '%s'", path_str);
|
||||
free(path_str);
|
||||
handleOAL = dlopen(path_str, RTLD_LAZY);
|
||||
if (handleOAL != NULL) {
|
||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
||||
} else {
|
||||
throwException(env, "Could not load OpenAL library");
|
||||
}
|
||||
free(path_str);
|
||||
return handleOAL != NULL;
|
||||
}
|
||||
|
||||
void UnLoadOpenAL() {
|
||||
|
|
|
@ -89,15 +89,16 @@ static CFBundleRef tryLoadFramework(JNIEnv *env) {
|
|||
return openal_bundle;
|
||||
}
|
||||
|
||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
printfDebugJava(env, "Testing '%s'", path_str);
|
||||
handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
(*env)->ReleaseStringUTFChars(env, path, path_str);
|
||||
if (handleOAL != NULL) {
|
||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
||||
} else {
|
||||
throwException(env, "Could not load OpenAL library");
|
||||
}
|
||||
(*env)->ReleaseStringUTFChars(env, path, path_str);
|
||||
return handleOAL != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,15 +51,16 @@ void *NativeGetFunctionPointer(const char *function) {
|
|||
return GetProcAddress(handleOAL, function);
|
||||
}
|
||||
|
||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||
char *path_str = GetStringNativeChars(env, path);
|
||||
printfDebugJava(env, "Testing '%s'", path_str);
|
||||
handleOAL = LoadLibrary(path_str);
|
||||
free(path_str);
|
||||
if (handleOAL != NULL) {
|
||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
||||
} else {
|
||||
throwException(env, "Could not load OpenAL library (%d)", GetLastError());
|
||||
}
|
||||
free(path_str);
|
||||
return handleOAL != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue