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 */
|
/* Platform dependent functions */
|
||||||
void *NativeGetFunctionPointer(const char *function);
|
void *NativeGetFunctionPointer(const char *function);
|
||||||
bool tryLoadLibrary(JNIEnv *env, jstring path);
|
void tryLoadLibrary(JNIEnv *env, jstring path);
|
||||||
void UnLoadOpenAL();
|
void UnLoadOpenAL();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -35,9 +35,7 @@
|
||||||
#include "extal.h"
|
#include "extal.h"
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nCreate(JNIEnv *env, jclass clazz, jstring oalPath) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nCreate(JNIEnv *env, jclass clazz, jstring oalPath) {
|
||||||
if (!tryLoadLibrary(env, oalPath)) {
|
tryLoadLibrary(env, oalPath);
|
||||||
throwException(env, "Could not load OpenAL library");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL_nDestroy(JNIEnv *env, jclass clazz) {
|
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);
|
return dlsym(handleOAL, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||||
char *path_str = GetStringNativeChars(env, path);
|
char *path_str = GetStringNativeChars(env, path);
|
||||||
printfDebugJava(env, "Testing '%s'", path_str);
|
printfDebugJava(env, "Testing '%s'", path_str);
|
||||||
|
free(path_str);
|
||||||
handleOAL = dlopen(path_str, RTLD_LAZY);
|
handleOAL = dlopen(path_str, RTLD_LAZY);
|
||||||
if (handleOAL != NULL) {
|
if (handleOAL != NULL) {
|
||||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
||||||
|
} else {
|
||||||
|
throwException(env, "Could not load OpenAL library");
|
||||||
}
|
}
|
||||||
free(path_str);
|
|
||||||
return handleOAL != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnLoadOpenAL() {
|
void UnLoadOpenAL() {
|
||||||
|
|
|
@ -89,15 +89,16 @@ static CFBundleRef tryLoadFramework(JNIEnv *env) {
|
||||||
return openal_bundle;
|
return openal_bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||||
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
|
const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
|
||||||
printfDebugJava(env, "Testing '%s'", path_str);
|
printfDebugJava(env, "Testing '%s'", path_str);
|
||||||
handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||||
|
(*env)->ReleaseStringUTFChars(env, path, path_str);
|
||||||
if (handleOAL != NULL) {
|
if (handleOAL != NULL) {
|
||||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
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);
|
return GetProcAddress(handleOAL, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tryLoadLibrary(JNIEnv *env, jstring path) {
|
void tryLoadLibrary(JNIEnv *env, jstring path) {
|
||||||
char *path_str = GetStringNativeChars(env, path);
|
char *path_str = GetStringNativeChars(env, path);
|
||||||
printfDebugJava(env, "Testing '%s'", path_str);
|
printfDebugJava(env, "Testing '%s'", path_str);
|
||||||
handleOAL = LoadLibrary(path_str);
|
handleOAL = LoadLibrary(path_str);
|
||||||
|
free(path_str);
|
||||||
if (handleOAL != NULL) {
|
if (handleOAL != NULL) {
|
||||||
printfDebugJava(env, "Found OpenAL at '%s'", path_str);
|
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