Created
April 26, 2021 06:28
-
-
Save malte0811/66ee9b3696cd03f886174f1e7ee31ef7 to your computer and use it in GitHub Desktop.
Mixins to debug "Pose stack not empty" crashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/TERDispatcherMixin.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/TERDispatcherMixin.java b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/TERDispatcherMixin.java | |
new file mode 100644 | |
--- /dev/null (date 1619418433751) | |
+++ b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/TERDispatcherMixin.java (date 1619418433751) | |
@@ -0,0 +1,30 @@ | |
+package blusunrize.immersiveengineering.mixin.coremods.client; | |
+ | |
+import blusunrize.immersiveengineering.StackDuck; | |
+import com.mojang.blaze3d.matrix.MatrixStack; | |
+import net.minecraft.client.renderer.IRenderTypeBuffer; | |
+import net.minecraft.client.renderer.tileentity.TileEntityRenderer; | |
+import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; | |
+import net.minecraft.tileentity.TileEntity; | |
+import org.spongepowered.asm.mixin.Mixin; | |
+import org.spongepowered.asm.mixin.injection.At; | |
+import org.spongepowered.asm.mixin.injection.Inject; | |
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
+ | |
+@Mixin(TileEntityRendererDispatcher.class) | |
+public class TERDispatcherMixin | |
+{ | |
+ @Inject(method = "render", at = @At("HEAD")) | |
+ private static <T extends TileEntity> | |
+ void preRender(TileEntityRenderer<T> rendererIn, T tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, CallbackInfo ci) | |
+ { | |
+ ((StackDuck)matrixStackIn).saveDepth(); | |
+ } | |
+ | |
+ @Inject(method = "render", at = @At("TAIL")) | |
+ private static <T extends TileEntity> | |
+ void postRender(TileEntityRenderer<T> rendererIn, T tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, CallbackInfo ci) | |
+ { | |
+ ((StackDuck)matrixStackIn).assertMatched(); | |
+ } | |
+} | |
Index: src/main/resources/immersiveengineering.mixins.json | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/main/resources/immersiveengineering.mixins.json b/src/main/resources/immersiveengineering.mixins.json | |
--- a/src/main/resources/immersiveengineering.mixins.json (revision e193a8caf9879afc9004005fdc909cbad6da80c6) | |
+++ b/src/main/resources/immersiveengineering.mixins.json (date 1619379406296) | |
@@ -22,7 +22,10 @@ | |
"accessors.TileEntityAccess", | |
"accessors.TNTEntityAccess", | |
"coremods.AbstractBlockStateMixin", | |
- "coremods.ServerWorldMixin" | |
+ "coremods.ServerWorldMixin", | |
+ "coremods.client.ERenderManagerMixin", | |
+ "coremods.client.MatrixStackHack", | |
+ "coremods.client.TERDispatcherMixin" | |
], | |
"client": [ | |
"accessors.client.FontResourceManagerAccess", | |
Index: src/main/java/blusunrize/immersiveengineering/StackDuck.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/main/java/blusunrize/immersiveengineering/StackDuck.java b/src/main/java/blusunrize/immersiveengineering/StackDuck.java | |
new file mode 100644 | |
--- /dev/null (date 1619418433759) | |
+++ b/src/main/java/blusunrize/immersiveengineering/StackDuck.java (date 1619418433759) | |
@@ -0,0 +1,8 @@ | |
+package blusunrize.immersiveengineering; | |
+ | |
+public interface StackDuck | |
+{ | |
+ void saveDepth(); | |
+ | |
+ void assertMatched(); | |
+} | |
Index: src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/MatrixStackHack.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/MatrixStackHack.java b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/MatrixStackHack.java | |
new file mode 100644 | |
--- /dev/null (date 1619418433767) | |
+++ b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/MatrixStackHack.java (date 1619418433767) | |
@@ -0,0 +1,70 @@ | |
+package blusunrize.immersiveengineering.mixin.coremods.client; | |
+ | |
+import blusunrize.immersiveengineering.StackDuck; | |
+import blusunrize.immersiveengineering.common.util.IELogger; | |
+import com.mojang.blaze3d.matrix.MatrixStack; | |
+import com.mojang.blaze3d.matrix.MatrixStack.Entry; | |
+import com.mojang.datafixers.util.Pair; | |
+import org.spongepowered.asm.mixin.Final; | |
+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; | |
+ | |
+import java.util.ArrayList; | |
+import java.util.Deque; | |
+import java.util.List; | |
+ | |
+@Mixin(MatrixStack.class) | |
+public class MatrixStackHack implements StackDuck | |
+{ | |
+ @Shadow | |
+ @Final | |
+ private Deque<Entry> stack; | |
+ private final List<Pair<String, StackTraceElement[]>> opsSinceLastEmpty = new ArrayList<>(); | |
+ | |
+ @Inject(method = "push", at = @At("HEAD")) | |
+ public void pushHead(CallbackInfo ci) | |
+ { | |
+ opsSinceLastEmpty.add(Pair.of("push", Thread.currentThread().getStackTrace())); | |
+ } | |
+ | |
+ @Inject(method = "pop", at = @At("TAIL")) | |
+ public void popHead(CallbackInfo ci) | |
+ { | |
+ if(stack.isEmpty()) | |
+ { | |
+ opsSinceLastEmpty.clear(); | |
+ } | |
+ else | |
+ { | |
+ opsSinceLastEmpty.add(Pair.of("pop", Thread.currentThread().getStackTrace())); | |
+ } | |
+ } | |
+ | |
+ private int lastDepth = -1; | |
+ | |
+ @Override | |
+ public void saveDepth() | |
+ { | |
+ lastDepth = stack.size(); | |
+ } | |
+ | |
+ @Override | |
+ public void assertMatched() | |
+ { | |
+ if(stack.size()!=lastDepth) | |
+ { | |
+ for(Pair<String, StackTraceElement[]> entry : opsSinceLastEmpty) | |
+ { | |
+ IELogger.logger.info("OP "+entry.getFirst()); | |
+ for(StackTraceElement e : entry.getSecond()) | |
+ { | |
+ IELogger.logger.info(" at "+e.toString()); | |
+ } | |
+ } | |
+ throw new RuntimeException(); | |
+ } | |
+ } | |
+} | |
Index: src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/ERenderManagerMixin.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/ERenderManagerMixin.java b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/ERenderManagerMixin.java | |
new file mode 100644 | |
--- /dev/null (date 1619418433739) | |
+++ b/src/main/java/blusunrize/immersiveengineering/mixin/coremods/client/ERenderManagerMixin.java (date 1619418433739) | |
@@ -0,0 +1,29 @@ | |
+package blusunrize.immersiveengineering.mixin.coremods.client; | |
+ | |
+import blusunrize.immersiveengineering.StackDuck; | |
+import com.mojang.blaze3d.matrix.MatrixStack; | |
+import net.minecraft.client.renderer.IRenderTypeBuffer; | |
+import net.minecraft.client.renderer.entity.EntityRendererManager; | |
+import net.minecraft.entity.Entity; | |
+import org.spongepowered.asm.mixin.Mixin; | |
+import org.spongepowered.asm.mixin.injection.At; | |
+import org.spongepowered.asm.mixin.injection.Inject; | |
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
+ | |
+@Mixin(EntityRendererManager.class) | |
+public class ERenderManagerMixin | |
+{ | |
+ @Inject(method = "renderEntityStatic", at = @At("HEAD")) | |
+ private <E extends Entity> | |
+ void preRender(E entityIn, double xIn, double yIn, double zIn, float rotationYawIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, CallbackInfo ci) | |
+ { | |
+ ((StackDuck)matrixStackIn).saveDepth(); | |
+ } | |
+ | |
+ @Inject(method = "renderEntityStatic", at = @At("TAIL")) | |
+ private <E extends Entity> | |
+ void postRender(E entityIn, double xIn, double yIn, double zIn, float rotationYawIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, CallbackInfo ci) | |
+ { | |
+ ((StackDuck)matrixStackIn).assertMatched(); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment