From 67957781a280e48ea62af6dc61fc6efbe62ca3bf Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 9 Jul 2006 08:31:49 +0000 Subject: [PATCH] Windows: don't cache the JNIEnv pointer in the message handle, but acquire it through the global JavaVM handle. --- src/native/common/common_tools.c | 6 ++++++ src/native/common/common_tools.h | 1 + src/native/win32/org_lwjgl_opengl_Display.c | 4 +--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/native/common/common_tools.c b/src/native/common/common_tools.c index 7c1a4418..44da186a 100644 --- a/src/native/common/common_tools.c +++ b/src/native/common/common_tools.c @@ -301,6 +301,12 @@ JavaVM *getJVM() { return jvm; } +JNIEnv *getThreadEnv() { + JNIEnv *env; + (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4); + return env; +} + JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { jvm = vm; return JNI_VERSION_1_4; diff --git a/src/native/common/common_tools.h b/src/native/common/common_tools.h index cba00639..d65e81e6 100644 --- a/src/native/common/common_tools.h +++ b/src/native/common/common_tools.h @@ -122,6 +122,7 @@ extern "C" { #endif extern JavaVM *getJVM(); +extern JNIEnv *getThreadEnv(); extern void initAttribList(attrib_list_t *list); extern void putAttrib(attrib_list_t *list, int attrib); diff --git a/src/native/win32/org_lwjgl_opengl_Display.c b/src/native/win32/org_lwjgl_opengl_Display.c index 6b974bf3..9da4f7bc 100644 --- a/src/native/win32/org_lwjgl_opengl_Display.c +++ b/src/native/win32/org_lwjgl_opengl_Display.c @@ -87,11 +87,10 @@ static LRESULT CALLBACK lwjglWindowProc(HWND hWnd, WPARAM wParam, LPARAM lParam) { - JNIEnv *env; jclass display_class; jmethodID handleMessage_method; LONG message_time; - env = (JNIEnv *)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA); + JNIEnv *env = getThreadEnv(); if (env != NULL && !(*env)->ExceptionOccurred(env)) { display_class = (*env)->FindClass(env, "org/lwjgl/opengl/Win32Display"); if (display_class != NULL) { @@ -186,7 +185,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateWindow(JNIEnv * throwException(env, "Failed to create the window."); return; } - SetWindowLongPtr(display_hwnd, GWLP_USERDATA, (LONG_PTR)env); display_hdc = GetDC(display_hwnd); ShowWindow(display_hwnd, SW_SHOWDEFAULT); UpdateWindow(display_hwnd);