Mekanism Generators

Mekanism Generators

97M Downloads

Custom packet using chemical stack opcional stream codec crashes with IndexOutOfBoundsException

alec016 opened this issue ยท 3 comments

commented

Issue description

I have a mod that integrates mekanism chemicals, sometimes on sync the chemical the game crashes and after try some times to load the world it loads as expected.(error message link below)

public record SUpdateChemicalComponentPacket(ChemicalStack chemical, BlockPos pos) implements CustomPacketPayload {

  public static final Type<SUpdateChemicalComponentPacket> TYPE = new Type<>(ModularMachineryReborn.rl("update_chemical"));

  @Override
  public Type<SUpdateChemicalComponentPacket> type() {
    return TYPE;
  }

  public static final StreamCodec<RegistryFriendlyByteBuf, SUpdateChemicalComponentPacket> CODEC = StreamCodec.composite(
      ChemicalStack.OPTIONAL_STREAM_CODEC,
      SUpdateChemicalComponentPacket::chemical,
      BlockPos.STREAM_CODEC,
      SUpdateChemicalComponentPacket::pos,
      SUpdateChemicalComponentPacket::new
  );

  public static void handle(SUpdateChemicalComponentPacket packet, IPayloadContext context) {
    // logic to load the synced stack here. i think its not relevant for the issue
 }

After looking so many times and try everything i could i couldnt find a cause on this packet, i can only think on chemical stack stream codec or in BlockPos stream codec. If you have any info about this issue let me know.
Thanks in advance for your time looking this issue.

Steps to reproduce

I dont know how to reproduce it, sometimes happens and sometimes not.

Minecraft version

1.21.1 (Latest)

NeoForge version

21.1.95

Mekanism version

10.7.7 (Latest)

Other relevant versions

My mod is Modular Machinery Reborn (Mekanism addon)

If a (crash)log is relevant for this issue, link it here: (It's almost always relevant)

https://mclo.gs/Twre4f3#L10571

commented

yeah, it is firing during connection
i couldnt reproduce the issue by myself, some users on atm10 has this issue while playing

commented

not sure how to debug that one... did it produce an actual crashlog file? That would be handy

We'd need to see the raw payload to work out what was missing

commented

Not sure what is causing this, I guess you could throw a breakpoint or log statement in here and see if it is firing during connection and if so maybe that is why? I believe the onContentsChanged might fire during deserialization (I forget), but even then I am not sure why the packet would fail like that.