From acc96b95c87a14cb811690d03db9c99123a68733 Mon Sep 17 00:00:00 2001 From: Roj234 <82699138+roj234@users.noreply.github.com> Date: Sun, 27 Jul 2025 00:40:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=AC=A1=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=B8=B8=E6=88=8F=E6=97=B6=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2=E7=9A=84=E9=97=AE=E9=A2=98=20(#4121)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Glavo --- .../java/org/jackhuang/hmcl/game/LauncherHelper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index 583ece830..b247a77e0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -59,6 +59,7 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import java.lang.ref.WeakReference; import static javafx.application.Platform.runLater; import static javafx.application.Platform.setImplicitExit; @@ -125,6 +126,9 @@ public final class LauncherHelper { } private void launch0() { + // https://github.com/HMCL-dev/HMCL/pull/4121 + PROCESSES.removeIf(it -> it.get() == null); + HMCLGameRepository repository = profile.getRepository(); DefaultDependencyManager dependencyManager = profile.getDependency(); AtomicReference version = new AtomicReference<>(MaintainTask.maintain(repository, repository.getResolvedVersion(selectedVersion))); @@ -209,7 +213,7 @@ public final class LauncherHelper { } }).thenAcceptAsync(process -> { // process is LaunchTask's result if (scriptFile == null) { - PROCESSES.add(process); + PROCESSES.add(new WeakReference<>(process)); if (launcherVisibility == LauncherVisibility.CLOSE) Launcher.stopApplication(); else @@ -896,10 +900,10 @@ public final class LauncherHelper { } - public static final Queue PROCESSES = new ConcurrentLinkedQueue<>(); + public static final Queue> PROCESSES = new ConcurrentLinkedQueue<>(); public static void stopManagedProcesses() { while (!PROCESSES.isEmpty()) - Optional.ofNullable(PROCESSES.poll()).ifPresent(ManagedProcess::stop); + Optional.ofNullable(PROCESSES.poll()).map(WeakReference::get).ifPresent(ManagedProcess::stop); } }