aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/NewtMacWindow.m
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-11-01 01:03:39 +0100
committerSven Gothel <[email protected]>2013-11-01 01:03:39 +0100
commitcc57413180edc4e5102f6729ccca6c4695d93e42 (patch)
tree0d9219db520229fca4009d5d2c2e05e4ed3b6227 /src/newt/native/NewtMacWindow.m
parentb0fa7977b154284334285daa642e114d7c9fca46 (diff)
Bug 882 - Crash on OSX when closing NEWT window - Check JavaVM and JNIEnv handles before usage in NewtMacWindow (Not the culprit .. but more safe)
Diffstat (limited to 'src/newt/native/NewtMacWindow.m')
-rw-r--r--src/newt/native/NewtMacWindow.m54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 35d3ffbc5..686e5d2b0 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -730,9 +730,14 @@ static jint mods2JavaMods(NSUInteger mods)
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ JNIEnv* env;
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ } else {
+ env = NULL;
+ }
if(NULL==env) {
- DBG_PRINT("sendKeyEvent: null JNIEnv\n");
+ DBG_PRINT("sendKeyEvent: JVM %p JNIEnv %p\n", jvmHandle, env);
return;
}
@@ -781,9 +786,14 @@ static jint mods2JavaMods(NSUInteger mods)
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ JNIEnv* env;
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ } else {
+ env = NULL;
+ }
if(NULL==env) {
- DBG_PRINT("sendMouseEvent: null JNIEnv\n");
+ DBG_PRINT("sendMouseEvent: JVM %p JNIEnv %p\n", jvmHandle, env);
return;
}
jint javaMods[] = { 0 } ;
@@ -851,9 +861,14 @@ static jint mods2JavaMods(NSUInteger mods)
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ JNIEnv* env;
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ } else {
+ env = NULL;
+ }
if(NULL==env) {
- DBG_PRINT("focusChanged: null JNIEnv\n");
+ DBG_PRINT("focusChanged: JVM %p JNIEnv %p\n", jvmHandle, env);
return;
}
@@ -1049,7 +1064,9 @@ static jint mods2JavaMods(NSUInteger mods)
javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject != NULL) {
jvmHandle = [view getJVMHandle];
- env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ }
}
}
@@ -1084,9 +1101,14 @@ static jint mods2JavaMods(NSUInteger mods)
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ JNIEnv* env;
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ } else {
+ env = NULL;
+ }
if(NULL==env) {
- DBG_PRINT("windowDidMove: null JNIEnv\n");
+ DBG_PRINT("windowDidMove: JVM %p JNIEnv %p\n", jvmHandle, env);
return;
}
@@ -1131,9 +1153,19 @@ static jint mods2JavaMods(NSUInteger mods)
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ JNIEnv* env = NULL;
+NS_DURING
+ if( NULL != jvmHandle ) {
+ env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], 1 /* asDaemon */, &shallBeDetached);
+ }
+NS_HANDLER
+ jvmHandle = NULL;
+ env = NULL;
+ [view setJVMHandle: NULL];
+ DBG_PRINT("windowWillClose: JVMHandler Exception\n");
+NS_ENDHANDLER
+ DBG_PRINT("windowWillClose: JVM %p JNIEnv %p\n", jvmHandle, env);
if(NULL==env) {
- DBG_PRINT("windowWillClose: null JNIEnv\n");
return NO;
}