LlamaLad7 / MixinExtras

Companion library to SpongePowered Mixin with many custom injectors for a more expressive experience.
MIT License
318 stars 17 forks source link

Crash with @Local (potentially due to static methods) #92

Closed amyavi closed 2 months ago

amyavi commented 2 months ago

This works:

import joptsimple.OptionParser;
import net.minecraft.server.Main;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(Main.class)
public abstract class MainMixin {
    @Inject(
            method = "main([Ljava/lang/String;)V", remap = false,
            at = @At(value = "INVOKE", target = "Ljoptsimple/OptionParser;nonOptions()Ljoptsimple/NonOptionArgumentSpec;"),
            locals = LocalCapture.CAPTURE_FAILHARD
    )
    private static void addOption(final String[] args, final CallbackInfo ci, OptionParser optionParser) {
        System.out.println("test");
    }
}

This causes a crash:

import com.llamalad7.mixinextras.sugar.Local;
import joptsimple.OptionParser;
import net.minecraft.server.Main;
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(Main.class)
public abstract class MainMixin {
    @Inject(
            method = "main([Ljava/lang/String;)V", remap = false,
            at = @At(value = "INVOKE", target = "Ljoptsimple/OptionParser;nonOptions()Ljoptsimple/NonOptionArgumentSpec;")
    )
    private static void addOption(final String[] args, final CallbackInfo ci, @Local OptionParser optionParser) {
        System.out.println("test");
    }
}

Crash log: https://gist.github.com/amyavi/9d893b67732bbe843956e9e3ca53b4cc

I have no clue what's causing the crash, but I believe this is because the method I'm injecting into is a static method. It also happens when using @WrapOperation.

LlamaLad7 commented 2 months ago

Seems you're pulling in ASM as a dependency and you shouldn't be. Please follow up in my discord if you can't get it working. This is not a MixinExtras issue.

LlamaLad7 commented 2 months ago

Seems fabric loader might not support servers on the new snapshot yet, which is causing this.

amyavi commented 2 months ago

The new snapshot seems to be pulling ASM as a dependency: image

Mojang don't seem to actually be using it anywhere, so it might be some sort of issue on their side.

LlamaLad7 commented 2 months ago

It's transitive. Fabric loader has an open PR to handle asm properly on the server so you just need to wait for that.

LlamaLad7 commented 2 months ago

Fixed in 0.16.3