Voxelum / minecraft-launcher-core-node

Provide packages to install Minecraft, launch Minecraft and more to build launcher with NodeJs/Electron!
https://docs.xmcl.app/en/core/
MIT License
174 stars 25 forks source link

[BUG] options.maxMemory is overwritten if options.extraJVMArgs is not present #221

Closed jamesonknutson closed 2 years ago

jamesonknutson commented 2 years ago

The maxMemory property of the options object passed to the launch function is overwritten if the options object does not also contain a valid extraJVMArgs property. This is because the generateArguments function appends the DEFAULT_EXTRA_JVM_ARGS constant to the array it returns if the aforementioned extraJVMArgs property is not present.

(lines 664 - 672)

// add extra jvm args
if (options.extraJVMArgs instanceof Array) {
    if (options.extraJVMArgs.some((v) => typeof v !== "string")) {
        throw new TypeError("Require extraJVMArgs be all string!");
    }
    cmd.push(...options.extraJVMArgs);
} else {
    cmd.push(...DEFAULT_EXTRA_JVM_ARGS);
}

This is only an issue because the DEFAULT_EXTRA_JVM_ARGS constant contains -Xmx2G in it.

(line 22)

export const DEFAULT_EXTRA_JVM_ARGS = Object.freeze([
    "-Xmx2G", // causes this bug
    "-XX:+UnlockExperimentalVMOptions",
    "-XX:+UseG1GC",
    "-XX:G1NewSizePercent=20",
    "-XX:G1ReservePercent=20",
    "-XX:MaxGCPauseMillis=50",
    "-XX:G1HeapRegionSize=32M"
]);

Submitting an ez-mode pull request in a moment to check for this edge case and exclude the "-Xmx2G" flag if options.maxMemory is present.

ci010 commented 2 years ago

This should be fixed in #223