Skip to content

Commit

Permalink
Improved thread stacktrace logging
Browse files Browse the repository at this point in the history
Closes #310
  • Loading branch information
RaphiMC committed Feb 4, 2025
1 parent 6ce1051 commit b00d2ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void warn() {
ImmediatelyFast.LOGGER.error("A mod tried to use the ImmediatelyFast batching API, but it is no longer available in 1.21.2.");
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.");
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.");
Thread.dumpStack();
ImmediatelyFast.LOGGER.error("Here is a stack trace to help you find the offending code:", new Exception());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,34 @@

import net.minecraft.client.gl.GlDebug;
import net.raphimc.immediatelyfast.ImmediatelyFast;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GlDebug.class)
public abstract class MixinGlDebug {

@Unique
private static long immediatelyFast$lastTime;

@Inject(method = "info", at = @At("RETURN"))
private static void printAdditionalInfo(CallbackInfo ci) {
@ModifyVariable(method = "enableDebug", at = @At("HEAD"), index = 1, argsOnly = true)
private static boolean enableSyncDebug(boolean sync) {
final GLCapabilities capabilities = GL.getCapabilities();
return sync || (ImmediatelyFast.config.debug_only_print_additional_error_information && (capabilities.GL_KHR_debug || capabilities.GL_ARB_debug_output));
}

@Redirect(method = "info", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", remap = false))
private static void appendStackTrace(Logger instance, String message, Object argument) {
if (ImmediatelyFast.config.debug_only_print_additional_error_information && System.currentTimeMillis() - immediatelyFast$lastTime > 1000) {
immediatelyFast$lastTime = System.currentTimeMillis();
Thread.dumpStack();
instance.info(message, argument, new Exception());
} else {
instance.info(message, argument);
}
}

Expand Down

0 comments on commit b00d2ba

Please sign in to comment.