From dfdf2cd672af017e4cbc969388350db099a284ca Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Tue, 2 Mar 2021 18:49:43 +0700 Subject: [PATCH] Default to gl4es 1.1.4 because of weird crashes --- Natives/JavaLauncher.c | 18 +++++++++++++++ Natives/egl_bridge.c | 4 ++-- Natives/utils.c | 51 ------------------------------------------ 3 files changed, 20 insertions(+), 53 deletions(-) diff --git a/Natives/JavaLauncher.c b/Natives/JavaLauncher.c index 558a8f65..d65a5d4a 100644 --- a/Natives/JavaLauncher.c +++ b/Natives/JavaLauncher.c @@ -11,6 +11,7 @@ #include "jni.h" #include "log.h" +#include "utils.h" #include "JavaLauncher.h" // PojavLancher: fixme: are these wrong? @@ -57,6 +58,7 @@ int launchJVM(int argc, char *argv[]) { // setenv("LIBGL_FB", "2", 1); setenv("LIBGL_MIPMAP", "3", 1); setenv("LIBGL_NORMALIZE", "1", 1); + setenv("LIBGL_DBGSHADERCONV", "1", 1); chdir("/var/mobile/Documents/minecraft"); @@ -113,6 +115,22 @@ int launchJVM(int argc, char *argv[]) { for (int i = 0; i < argc; i++) { margv[margc++] = argv[i]; } + } else { + // Locate gl4es library name: + // Reverse the loop, since it is overridable. +/* + char* opengl_prefix = "-Dorg.lwjgl.opengl.libname="; + for (int i = argc - 1; i >= 0; i--) { + if (strncmp(opengl_prefix, argv[i], strlen(opengl_prefix)) == 0) { + strtok(argv[i], "="); + setenv("POJAV_OPENGL_LIBNAME", strtok(NULL, "="), 1); + break; + } + } +*/ +setenv("POJAV_OPENGL_LIBNAME", "libgl4es_114.dylib", 1); + + debug("OpenGL library name: %s", getenv("POJAV_OPENGL_LIBNAME")); } // Load java diff --git a/Natives/egl_bridge.c b/Natives/egl_bridge.c index a7ea02e8..382bd150 100644 --- a/Natives/egl_bridge.c +++ b/Natives/egl_bridge.c @@ -192,8 +192,8 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* debug("First frame error: %p", eglGetError()); #endif if (success == EGL_TRUE) { - GL4ES_HANDLE = dlopen("libGL.dylib", RTLD_GLOBAL); - debug("libGL = %p", GL4ES_HANDLE); + GL4ES_HANDLE = dlopen(getenv("POJAV_OPENGL_LIBNAME"), RTLD_GLOBAL); + debug("libGL=%p", GL4ES_HANDLE); gl4esInitialize_func *gl4esInitialize = (gl4esInitialize_func*) dlsym(GL4ES_HANDLE, "initialize_gl4es"); // debug("initialize_gl4es = %p", gl4esInitialize); diff --git a/Natives/utils.c b/Natives/utils.c index 2119f17a..57574c5c 100644 --- a/Natives/utils.c +++ b/Natives/utils.c @@ -8,8 +8,6 @@ #include "utils.h" -typedef int (*Main_Function_t)(int, char**); - long shared_awt_surface; char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray) { @@ -97,52 +95,3 @@ JNIEXPORT jint JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_chdir(JNIEnv *env (*env)->ReleaseStringUTFChars(env, nameStr, name); return retval; } - -JNIEXPORT jint JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_executeBinary(JNIEnv *env, jclass clazz, jobjectArray cmdArgs) { - jclass exception_cls = (*env)->FindClass(env, "java/lang/UnsatisfiedLinkError"); - jstring execFile = (*env)->GetObjectArrayElement(env, cmdArgs, 0); - - char *exec_file_c = (char*) (*env)->GetStringUTFChars(env, execFile, 0); - void *exec_binary_handle = dlopen(exec_file_c, RTLD_LAZY); - - // (*env)->ReleaseStringUTFChars(env, ldLibraryPath, ld_library_path_c); - (*env)->ReleaseStringUTFChars(env, execFile, exec_file_c); - - char *exec_error_c = dlerror(); - if (exec_error_c != NULL) { - LOGE("Error: %s", exec_error_c); - (*env)->ThrowNew(env, exception_cls, exec_error_c); - return -1; - } - - Main_Function_t Main_Function; - Main_Function = (Main_Function_t) dlsym(exec_binary_handle, "main"); - - exec_error_c = dlerror(); - if (exec_error_c != NULL) { - LOGE("Error: %s", exec_error_c); - (*env)->ThrowNew(env, exception_cls, exec_error_c); - return -1; - } - - int cmd_argv = (*env)->GetArrayLength(env, cmdArgs); - char **cmd_args_c = convert_to_char_array(env, cmdArgs); - int result = Main_Function(cmd_argv, cmd_args_c); - free_char_array(env, cmdArgs, cmd_args_c); - return result; -} - -// METHOD 2 -/* -JNIEXPORT jint JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_executeForkedBinary(JNIEnv *env, jclass clazz, jobjectArray cmdArgs) { - int x, status; - x = fork(); - if (x > 0) { - wait(&status); - } else { - execvpe(); - } - return status; -} -*/ -