diff --git a/src/native/common/extal.h b/src/native/common/extal.h index 3c9a7711..13b30767 100644 --- a/src/native/common/extal.h +++ b/src/native/common/extal.h @@ -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 diff --git a/src/native/common/org_lwjgl_openal_AL.c b/src/native/common/org_lwjgl_openal_AL.c index 793a9565..3db426e8 100644 --- a/src/native/common/org_lwjgl_openal_AL.c +++ b/src/native/common/org_lwjgl_openal_AL.c @@ -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) { diff --git a/src/native/linux/linux_al.c b/src/native/linux/linux_al.c index 9c50bd84..d0d412f7 100644 --- a/src/native/linux/linux_al.c +++ b/src/native/linux/linux_al.c @@ -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() { diff --git a/src/native/macosx/macosx_al.c b/src/native/macosx/macosx_al.c index 51364384..316d9464 100644 --- a/src/native/macosx/macosx_al.c +++ b/src/native/macosx/macosx_al.c @@ -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; } /** diff --git a/src/native/windows/windows_al.c b/src/native/windows/windows_al.c index 42717c08..c5ea58dc 100644 --- a/src/native/windows/windows_al.c +++ b/src/native/windows/windows_al.c @@ -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; } /**