mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 06:05:10 -04:00
JNI: Attach Android thread to JRE, is it safe?
This commit is contained in:
parent
1690938b3b
commit
8a6d23a06f
@ -154,7 +154,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv*
|
||||
printf("First frame error: %p\n", eglGetError());
|
||||
#endif
|
||||
|
||||
isEglMakeCurrentCalled = 1;
|
||||
isInputReady = true;
|
||||
|
||||
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
@ -3,7 +3,12 @@
|
||||
#include "utils.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_LWJGLInputSender_sendDataToJRE(JNIEnv* env, jclass clazz, jint type, jstring data) {
|
||||
if (isEglMakeCurrentCalled == 1) {
|
||||
if (isInputReady) {
|
||||
if (!isAndroidThreadAttached) {
|
||||
(*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &runtimeJNIEnvPtr, NULL);
|
||||
isAndroidThreadAttached = true;
|
||||
}
|
||||
|
||||
// Convert Dalvik string to JRE string: should or use directly?
|
||||
char *data_c = (char*)(*env)->GetStringUTFChars(env, data, 0);
|
||||
jstring data_jre = (*runtimeJNIEnvPtr)->NewStringUTF(runtimeJNIEnvPtr, data_c);
|
||||
|
@ -68,7 +68,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
*/
|
||||
} else if (dalvikJavaVMPtr != vm) {
|
||||
runtimeJavaVMPtr = vm;
|
||||
(*vm)->GetEnv(vm, (void**) &runtimeJNIEnvPtr, JNI_VERSION_1_4);
|
||||
// (*vm)->GetEnv(vm, (void**) &runtimeJNIEnvPtr, JNI_VERSION_1_4);
|
||||
}
|
||||
LOGD("JNI_OnLoad returning()");
|
||||
return JNI_VERSION_1_4;
|
||||
|
@ -1,13 +1,16 @@
|
||||
#ifndef _BINARY_UTILS_H_
|
||||
#define _BINARY_UTILS_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
JavaVM *runtimeJavaVMPtr;
|
||||
JNIEnv *runtimeJNIEnvPtr;
|
||||
|
||||
JavaVM *dalvikJavaVMPtr;
|
||||
JNIEnv *dalvikJNIEnvPtr;
|
||||
|
||||
int isEglMakeCurrentCalled;
|
||||
bool isInputReady;
|
||||
bool isAndroidThreadAttached;
|
||||
|
||||
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
|
||||
|
Loading…
x
Reference in New Issue
Block a user