diff options
Diffstat (limited to 'src/jogl/native/JoglCommon.c')
-rw-r--r-- | src/jogl/native/JoglCommon.c | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/jogl/native/JoglCommon.c b/src/jogl/native/JoglCommon.c index 719e0df56..d9f5edd49 100644 --- a/src/jogl/native/JoglCommon.c +++ b/src/jogl/native/JoglCommon.c @@ -11,48 +11,63 @@ static jclass runtimeExceptionClz=NULL; static JavaVM *_jvmHandle = NULL; static int _jvmVersion = 0; +void JoglCommon_init(JNIEnv *env) { + if(NULL==runtimeExceptionClz) { + jclass c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + JoglCommon_FatalError(env, "JOGL: can't find %s", ClazzNameRuntimeException); + } + runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==runtimeExceptionClz) { + JoglCommon_FatalError(env, "JOGL: can't use %s", ClazzNameRuntimeException); + } + } + if(0 != (*env)->GetJavaVM(env, &_jvmHandle)) { + JoglCommon_FatalError(env, "JOGL: can't fetch JavaVM handle"); + } else { + _jvmVersion = (*env)->GetVersion(env); + } +} void JoglCommon_FatalError(JNIEnv *env, const char* msg, ...) { char buffer[512]; va_list ap; + int shallBeDetached = 0; + + if(NULL == env) { + env = JoglCommon_GetJNIEnv (&shallBeDetached); + } va_start(ap, msg); vsnprintf(buffer, sizeof(buffer), msg, ap); va_end(ap); fprintf(stderr, "%s\n", buffer); - (*env)->FatalError(env, buffer); + if(NULL != env) { + (*env)->FatalError(env, buffer); + JoglCommon_ReleaseJNIEnv (shallBeDetached); + } } void JoglCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) { char buffer[512]; va_list ap; + int shallBeDetached = 0; + + if(NULL == env) { + env = JoglCommon_GetJNIEnv (&shallBeDetached); + } va_start(ap, msg); vsnprintf(buffer, sizeof(buffer), msg, ap); va_end(ap); - (*env)->ThrowNew(env, runtimeExceptionClz, buffer); -} - -void JoglCommon_init(JNIEnv *env) { - if(NULL==runtimeExceptionClz) { - jclass c = (*env)->FindClass(env, ClazzNameRuntimeException); - if(NULL==c) { - JoglCommon_FatalError(env, "JOGL: can't find %s", ClazzNameRuntimeException); - } - runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - if(NULL==runtimeExceptionClz) { - JoglCommon_FatalError(env, "JOGL: can't use %s", ClazzNameRuntimeException); - } - } - if(0 != (*env)->GetJavaVM(env, &_jvmHandle)) { - JoglCommon_FatalError(env, "JOGL: can't fetch JavaVM handle"); - } else { - _jvmVersion = (*env)->GetVersion(env); + if(NULL != env) { + (*env)->ThrowNew(env, runtimeExceptionClz, buffer); + JoglCommon_ReleaseJNIEnv (shallBeDetached); } } @@ -110,7 +125,6 @@ JNIEnv* JoglCommon_GetJNIEnv (int * shallBeDetached) void JoglCommon_ReleaseJNIEnv (int shallBeDetached) { if(NULL == _jvmHandle) { fprintf(stderr, "JOGL: No JavaVM handle registered, call JoglCommon_init(..) 1st"); - return NULL; } if(shallBeDetached) { |