Skip to content

Commit

Permalink
Fix EffectRenderer and RenderGlobal leaking world instance when leavi…
Browse files Browse the repository at this point in the history
…ng world
  • Loading branch information
tth05 committed Nov 14, 2023
1 parent e63656d commit 0db41c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class LoadingConfig {
public boolean fixThaumcraftGolemMarkerLoading;
public boolean fixTimeCommandWithGC;
public boolean fixUnfocusedFullscreen;
public boolean fixRenderersWorldLeak;
public boolean fixForgeUpdateChecker;
public boolean fixUrlDetection;
public boolean fixVanillaUnprotectedGetBlock;
Expand Down Expand Up @@ -289,6 +290,7 @@ public LoadingConfig(File file) {
fixThaumcraftAspectSorting = config.get(Category.FIXES.toString(), "fixThaumcraftAspectSorting", true, "Fix Thaumcraft Aspects being sorted by tag instead of by name").getBoolean();
fixThaumcraftGolemMarkerLoading = config.get(Category.FIXES.toString(), "fixThaumcraftGolemMarkerLoading", true, "Fix golem's marker loading failure when dimensionId larger than MAX_BYTE").getBoolean();
fixUnfocusedFullscreen = config.get(Category.FIXES.toString(), "fixUnfocusedFullscreen", true, "Fix exiting fullscreen when you tab out of the game").getBoolean();
fixRenderersWorldLeak = config.get(Category.FIXES.toString(), "fixRenderersWorldLeak", true, "Fix EffectRenderer and RenderGlobal leaking world instance when leaving world").getBoolean();
fixUrlDetection = config.get(Category.FIXES.toString(), "fixUrlDetection", true, "Fix URISyntaxException in forge.").getBoolean();
fixVanillaUnprotectedGetBlock = config.get(Category.FIXES.toString(), "fixVanillaUnprotectedGetBlock", true, "Fixes various unchecked vanilla getBlock() methods").getBoolean();
fixVillageUncheckedGetBlock = config.get(Category.FIXES.toString(), "fixVillageUncheckedGetBlock", true, "Fixes village unchecked getBlock() calls").getBoolean();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public enum Mixins {
FIX_UNFOCUSED_FULLSCREEN(new Builder("Fix Unfocused Fullscreen").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinMinecraft_UnfocusedFullscreen").setSide(Side.CLIENT)
.setApplyIf(() -> Common.config.fixUnfocusedFullscreen).addTargetedMod(TargetedMod.VANILLA)),
FIX_RENDERERS_WORLD_LEAK(new Builder("Fix Renderers World Leak").setPhase(Phase.EARLY)
.addMixinClasses("minecraft.MixinMinecraft_ClearRenderersWorldLeak").setSide(Side.CLIENT)
.setApplyIf(() -> Common.config.fixRenderersWorldLeak).addTargetedMod(TargetedMod.VANILLA)),
FIX_OPTIFINE_CHUNKLOADING_CRASH(new Builder("Fix Optifine Chunkloading Crash").setPhase(Phase.EARLY)
.setApplyIf(() -> Common.config.fixOptifineChunkLoadingCrash).setSide(Side.CLIENT)
.addTargetedMod(TargetedMod.VANILLA).addTargetedMod(TargetedMod.OPTIFINE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.RenderGlobal;

import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Minecraft.class)
public abstract class MixinMinecraft_ClearRenderersWorldLeak {

@Shadow
public EffectRenderer effectRenderer;

@Shadow
public RenderGlobal renderGlobal;

@Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/Minecraft;theWorld:Lnet/minecraft/client/multiplayer/WorldClient;",
opcode = Opcodes.PUTFIELD))
private void hodgepodge$fixRenderersWorldLeak(WorldClient worldClient, String loadingMessage, CallbackInfo ci) {
if (worldClient == null) {
if (renderGlobal != null) {
renderGlobal.setWorldAndLoadRenderers(null);
}

if (effectRenderer != null) {
effectRenderer.clearEffects(null);
}
}
}
}

0 comments on commit 0db41c7

Please sign in to comment.