aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xloader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java21
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java24
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java5
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java7
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java5
-rwxr-xr-xmod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java1
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java8
7 files changed, 51 insertions, 20 deletions
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
index e4adbf94..4a7ef695 100755
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
@@ -20,10 +20,7 @@ package kr.syeyoung.dungeonsguide.launcher;
import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager;
import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.NoSuitableLoaderFoundException;
-import kr.syeyoung.dungeonsguide.launcher.exceptions.NoVersionFoundException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.*;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiChooseVersion;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiDisplayer;
import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiLoadingError;
@@ -67,6 +64,7 @@ public class Main
public static final String DOMAIN = "https://v2.dungeons.guide/api";
private static Main main;
+ private static volatile boolean referenceLeak = false;
private static File configDir;
@@ -169,10 +167,17 @@ public class Main
GuiDisplayer.INSTANCE.displayGui(new GuiChooseVersion(new RuntimeException("just unloaded")));
})
.build()));
- if (currentLoader != null) {
- currentLoader.unloadDungeonsGuide();
+ try {
+ if (currentLoader != null) {
+ currentLoader.unloadDungeonsGuide();
+ }
+ } catch (DungeonsGuideUnloadingException e) {
+ if (e.getCause() instanceof ReferenceLeakedException) {
+ referenceLeak = true;
+ currentLoader = null;
+ }
+ throw e;
}
- currentLoader = null;
}
@@ -224,8 +229,6 @@ public class Main
load(newLoader);
} catch (DungeonsGuideLoadingException | DungeonsGuideUnloadingException e) {
dgInterface = null;
-// currentLoader = null;
-
e.printStackTrace();
throw e;
} finally {
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java
new file mode 100644
index 00000000..a6b730ca
--- /dev/null
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/exceptions/ReferenceLeakedException.java
@@ -0,0 +1,24 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.launcher.exceptions;
+
+public class ReferenceLeakedException extends Exception {
+ public ReferenceLeakedException(String message) {super(message);}
+ public ReferenceLeakedException(Throwable cause) {super(cause);}
+}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
index 6c29b1f6..93368801 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/JarLoader.java
@@ -21,6 +21,7 @@ package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
import kr.syeyoung.dungeonsguide.launcher.util.ProgressStateHolder;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.apache.commons.io.IOUtils;
@@ -109,9 +110,9 @@ public class JarLoader implements IDGLoader {
dgInterface = null;
System.gc();// pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
- t.clear();
phantomReference = null;
+ if (t == null) throw new DungeonsGuideUnloadingException(new ReferenceLeakedException("Reference Leaked")); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ t.clear();
}
@Override
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
index 1a88f475..f0e099e4 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/LocalLoader.java
@@ -21,6 +21,7 @@ package kr.syeyoung.dungeonsguide.launcher.loader;
import kr.syeyoung.dungeonsguide.launcher.DGInterface;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
import kr.syeyoung.dungeonsguide.launcher.util.ProgressStateHolder;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.apache.commons.io.IOUtils;
@@ -89,7 +90,7 @@ public class LocalLoader implements IDGLoader {
if (dgInterface == null && classLoader == null) return;
try {
if (dgInterface != null)
- dgInterface.unload();
+ dgInterface.unload();
} catch (Throwable e) {
dgInterface = null;
throw new DungeonsGuideUnloadingException(e);
@@ -100,9 +101,9 @@ public class LocalLoader implements IDGLoader {
dgInterface = null;
System.gc(); // pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
- t.clear();
phantomReference = null;
+ if (t == null) throw new DungeonsGuideUnloadingException(new ReferenceLeakedException("Reference Leaked")); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ t.clear();
}
@Override
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
index 667340d6..6e26239f 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/RemoteLoader.java
@@ -25,6 +25,7 @@ import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException;
import kr.syeyoung.dungeonsguide.launcher.exceptions.NoVersionFoundException;
+import kr.syeyoung.dungeonsguide.launcher.exceptions.ReferenceLeakedException;
import kr.syeyoung.dungeonsguide.launcher.util.ProgressStateHolder;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.apache.commons.io.IOUtils;
@@ -145,9 +146,9 @@ public class RemoteLoader implements IDGLoader {
dgInterface = null;
System.gc();// pls do
Reference<? extends ClassLoader> t = refQueue.poll();
- if (t == null) throw new DungeonsGuideUnloadingException("Reference Leaked"); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
- t.clear();
phantomReference = null;
+ if (t == null) throw new DungeonsGuideUnloadingException(new ReferenceLeakedException("Reference Leaked")); // Why do you have to be that strict? Well, to tell them to actually listen on DungeonsGuideReloadListener. If it starts causing issues then I will remove check cus it's not really loaded (classes are loaded by child classloader)
+ t.clear();
}
@Override
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
index 7a7ba7fb..b0d67ab0 100755
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
@@ -304,6 +304,7 @@ public class DungeonsGuide implements DGInterface {
StompManager.getInstance().cleanup();
// have FUN!
+
for (Object registeredListener : registeredListeners) {
MinecraftForge.EVENT_BUS.unregister(registeredListener);
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java
index 54ba4f8a..676682ff 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java
@@ -93,16 +93,16 @@ public class PacketInjector extends ChannelDuplexHandler {
super.write(ctx, msg, promise);
}
- private ChannelPipeline thePipeline;
+
@SubscribeEvent
public void onServerConnect(FMLNetworkEvent.ClientConnectedToServerEvent event) {
- (thePipeline =event.manager.channel().pipeline()).addBefore("packet_handler", "dg_packet_handler", this);
+ event.manager.channel().pipeline().addBefore("packet_handler", "dg_packet_handler", this);
}
public void cleanup() {
try {
- if (thePipeline != null)
- thePipeline.remove("dg_packet_handler");
+ if (Minecraft.getMinecraft().getNetHandler() != null)
+ Minecraft.getMinecraft().getNetHandler().getNetworkManager().channel().pipeline().remove("dg_packet_handler");
} catch (Exception e) {
}