Skip to content

Commit b00d2ba

Browse files
committed
Improved thread stacktrace logging
Closes #310
1 parent 6ce1051 commit b00d2ba

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

common/src/main/java/net/raphimc/immediatelyfast/apiimpl/BatchingAccessImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void warn() {
6363
ImmediatelyFast.LOGGER.error("A mod tried to use the ImmediatelyFast batching API, but it is no longer available in 1.21.2.");
6464
ImmediatelyFast.LOGGER.error("Mojang added basic batching into the DrawContext class. ImmediatelyFast now uses and extends this system, so this method is no longer needed.");
6565
ImmediatelyFast.LOGGER.error("To migrate your mod, simply remove all calls to the ImmediatelyFast batching API and make sure to use the DrawContext for your HUD rendering.");
66-
Thread.dumpStack();
66+
ImmediatelyFast.LOGGER.error("Here is a stack trace to help you find the offending code:", new Exception());
6767
}
6868
}
6969

common/src/main/java/net/raphimc/immediatelyfast/injection/mixins/core/MixinGlDebug.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,34 @@
1919

2020
import net.minecraft.client.gl.GlDebug;
2121
import net.raphimc.immediatelyfast.ImmediatelyFast;
22+
import org.lwjgl.opengl.GL;
23+
import org.lwjgl.opengl.GLCapabilities;
24+
import org.slf4j.Logger;
2225
import org.spongepowered.asm.mixin.Mixin;
2326
import org.spongepowered.asm.mixin.Unique;
2427
import org.spongepowered.asm.mixin.injection.At;
25-
import org.spongepowered.asm.mixin.injection.Inject;
26-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
28+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
29+
import org.spongepowered.asm.mixin.injection.Redirect;
2730

2831
@Mixin(GlDebug.class)
2932
public abstract class MixinGlDebug {
3033

3134
@Unique
3235
private static long immediatelyFast$lastTime;
3336

34-
@Inject(method = "info", at = @At("RETURN"))
35-
private static void printAdditionalInfo(CallbackInfo ci) {
37+
@ModifyVariable(method = "enableDebug", at = @At("HEAD"), index = 1, argsOnly = true)
38+
private static boolean enableSyncDebug(boolean sync) {
39+
final GLCapabilities capabilities = GL.getCapabilities();
40+
return sync || (ImmediatelyFast.config.debug_only_print_additional_error_information && (capabilities.GL_KHR_debug || capabilities.GL_ARB_debug_output));
41+
}
42+
43+
@Redirect(method = "info", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", remap = false))
44+
private static void appendStackTrace(Logger instance, String message, Object argument) {
3645
if (ImmediatelyFast.config.debug_only_print_additional_error_information && System.currentTimeMillis() - immediatelyFast$lastTime > 1000) {
3746
immediatelyFast$lastTime = System.currentTimeMillis();
38-
Thread.dumpStack();
47+
instance.info(message, argument, new Exception());
48+
} else {
49+
instance.info(message, argument);
3950
}
4051
}
4152

0 commit comments

Comments
 (0)