diff --git a/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java b/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java index d2ef31ad3..da91fb1dc 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java +++ b/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java @@ -56,13 +56,18 @@ public class JREUtils Log.v("jrelog","Log starts here"); Thread t = new Thread(new Runnable(){ int failTime = 0; + ProcessBuilder logcatPb; @Override public void run() { try { + if (logcatPb == null) { + logcatPb = new ProcessBuilder().command("logcat", /* "-G", "1mb", */ "-v", "brief", "*:S").redirectErrorStream(true); + } + Log.i("jrelog-logcat","Clearing logcat"); new ProcessBuilder().command("logcat", "-c").redirectErrorStream(true).start(); Log.i("jrelog-logcat","Starting logcat"); - java.lang.Process p = new ProcessBuilder().command("logcat", /* "-G", "1mb", */ "-v", "brief", "*:S").redirectErrorStream(true).start(); + java.lang.Process p = logcatPb.start(); // idk which better, both have a bug that printf(\n) in a single line /* @@ -103,10 +108,10 @@ public class JREUtils return; } } catch (Throwable e) { - Log.e("jrelog-logcat", "IOException on logging thread"); + Log.e("jrelog-logcat", "Exception on logging thread"); e.printStackTrace(); - act.appendlnToLog("IOException on logging thread:\n" + Log.getStackTraceString(e)); + act.appendlnToLog("Exception on logging thread:\n" + Log.getStackTraceString(e)); } } }); diff --git a/app/src/main/jni/input_bridge.c b/app/src/main/jni/input_bridge.c index d05c1a13a..92f0205de 100644 --- a/app/src/main/jni/input_bridge.c +++ b/app/src/main/jni/input_bridge.c @@ -10,12 +10,11 @@ struct GLFWInputEvent { int i1, i2, i3, i4; double d1, d2; }; -struct GLFWInputEvent* glfwInputEventArr; +struct char* glfwInputEventArr[100]; +int glfwInputEventIndex; int *grabCursorX, *grabCursorY, *lastCursorX, *lastCursorY; -int glfwInputEventIndex; - #define EVENT_TYPE_CHAR 1000 #define EVENT_TYPE_CHAR_MODS 1001 #define EVENT_TYPE_CURSOR_ENTER 1002 @@ -124,24 +123,25 @@ void invokeCursorPos(int x, int y) { return; } } - if (!isUseStackQueueCall) { + if (!isUseStackQueueCall && GLFW_invoke_CursorPos) { GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? *grabCursorX : x), (double) (isGrabbing ? *grabCursorY : y)); } *lastCursorX = x; *lastCursorY = y; } +void addInputToQueue(GLFWInputEvent event) { + if (glfwInputEventIndex++ + glfwInputEventArr[glfwInputEventIndex] = (char*) event; +} + JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueue) { glfwInputEventIndex = -1; - isUseStackQueueCall = 1; - // isUseStackQueueCall = (int) isUseStackQueue; + // isUseStackQueueCall = 1; + isUseStackQueueCall = (int) isUseStackQueue; if (isUseStackQueue) { isPrepareGrabPos = true; - - glfwInputEventArr = calloc(100, sizeof(struct GLFWInputEvent)); - } - - if (isAndroid) { + } else if (isAndroid) { firstJavaVM = dalvikJavaVMPtr; firstJNIEnv = dalvikJNIEnvPtr_ANDROID; secondJavaVM = runtimeJavaVMPtr; @@ -314,12 +314,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendFramebufferS JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(JNIEnv* env, jclass clazz, jint key, jint scancode, jint action, jint mods) { if (GLFW_invoke_Key && isInputReady) { if (isUseStackQueueCall) { - struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++]; + struct GLFWInputEvent curr; curr.type = EVENT_TYPE_KEY; curr.i1 = key; curr.i2 = scancode; curr.i3 = action; curr.i4 = mods; + addInputToQueue(curr); } else GLFW_invoke_Key(showingWindow, key, scancode, action, mods); }