Skip to content

Commit 29401d4

Browse files
authored
ugly workaround
1 parent d3bce3a commit 29401d4

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

  • app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
287287
List<String> userArgs = getJavaArgs(activity, runtimeHome, userArgsString);
288288

289289
//Remove arguments that can interfere with the good working of the launcher
290-
purgeArg(userArgs,"-Xms");
291-
purgeArg(userArgs,"-Xmx");
290+
292291
purgeArg(userArgs,"-d32");
293292
purgeArg(userArgs,"-d64");
294293
purgeArg(userArgs, "-Xint");
@@ -302,8 +301,8 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
302301
purgeArg(userArgs, "-XX:ActiveProcessorCount");
303302

304303
//Add automatically generated args
305-
userArgs.add("-Xms" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
306-
userArgs.add("-Xmx" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
304+
if(hasArg(userArgs, "-Xms") == null) userArgs.add("-Xms" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
305+
if(hasArg(userArgs, "-Xmx") == null) userArgs.add("-Xmx" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
307306
if(LOCAL_RENDERER != null) userArgs.add("-Dorg.lwjgl.opengl.libname=" + graphicsLib);
308307

309308
// Force LWJGL to use the Freetype library intended for it, instead of using the one
@@ -312,6 +311,7 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
312311

313312
// Some phones are not using the right number of cores, fix that
314313
userArgs.add("-XX:ActiveProcessorCount=" + java.lang.Runtime.getRuntime().availableProcessors());
314+
315315
// Disable Sodium's LWJGL check to prevent a crash
316316
userArgs.add("-Dsodium.checks.issue2561=false");
317317

@@ -323,7 +323,7 @@ public static void launchJavaVM(final AppCompatActivity activity, final Runtime
323323
JREUtils.setupExitMethod(activity.getApplication());
324324
JREUtils.initializeHooks();
325325
chdir(gameDirectory == null ? Tools.DIR_GAME_NEW : gameDirectory.getAbsolutePath());
326-
userArgs.add(0,"java"); //argv[0] is the program name according to C standard.
326+
userArgs.add(0, "java"); //argv[0] is the program name according to C standard.
327327

328328
final int exitCode = VMLauncher.launchJVM(userArgs.toArray(new String[0]));
329329
Logger.appendToLog("Java Exit code: " + exitCode);
@@ -487,19 +487,29 @@ public static String loadGraphicsLibrary(){
487487
return renderLibrary;
488488
}
489489

490+
private static Iterator<String> hasArg(List<String> argList, String argStart) {
491+
Iterator<String> args = argList.iterator();
492+
493+
while(args.hasNext()) {
494+
if(args.next().startsWith(argStart)) return args;
495+
}
496+
497+
return null;
498+
}
499+
490500
/**
491501
* Remove the argument from the list, if it exists
492502
* If the argument exists multiple times, they will all be removed.
493503
* @param argList The argument list to purge
494504
* @param argStart The argument to purge from the list.
495505
*/
496506
private static void purgeArg(List<String> argList, String argStart) {
497-
Iterator<String> args = argList.iterator();
498-
while(args.hasNext()) {
499-
String arg = args.next();
500-
if(arg.startsWith(argStart)) args.remove();
501-
}
507+
Iterator<String> arg = hasArg(argList, argStart);
508+
if(arg == null) return;
509+
510+
arg.remove();
502511
}
512+
503513
private static final int EGL_OPENGL_ES_BIT = 0x0001;
504514
private static final int EGL_OPENGL_ES2_BIT = 0x0004;
505515
private static final int EGL_OPENGL_ES3_BIT_KHR = 0x0040;

0 commit comments

Comments
 (0)