Jump to content

1.12 How to Isolate Issues with Packets?


4sterism

Recommended Posts

People on my server have been getting this issue alot: java.lang.IndexOutOfBoundsException: readerIndex(32) + length(1) exceeds writerIndex(32): PooledUnsafeDirectByteBuf(ridx: 32, widx: 32, cap: 32). But the debug log doesnt provide anything useful for me to find the source of the problem. I know the problem is with one of my packets, how do I find the packet with the 32 index?

Link to comment
Share on other sites

9 hours ago, 4sterism said:

People on my server

Question:

Did you write your own mod

or

Do you just run a modded server?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

8 hours ago, diesieben07 said:

The problem is that you are trying to read data where there is none. This usually means you have a mismatch between the data you are sending and the data you are trying to read on the other side.

Again: Show your code.

Will do, I look at all my Handlers and post up the one soon.

Link to comment
Share on other sites

 @Override
        public NBTTagCompound getNBT() {
            nbt.setFloat(MANA, mana);
            nbt.setFloat(ENERGY, energy);
            nbt.setInteger(LEVEL, level);
            nbt.setInteger(EXP, exp);
            nbt.setInteger(RARITY, rarity);
            nbt.setString(UUID, uuid);
            nbt.setString(NAME, name);
            nbt.setBoolean(MOB_SAVED_ONCE, true);
            nbt.setInteger(CURRENT_MAP_ID, currentMapId);
            nbt.setBoolean(EQUIPS_CHANGED, equipsChanged);
            nbt.setFloat(DMG_DONE_BY_NON_PLAYERS, dmgByNonPlayers);

            if (unit != null) {
                NBTTagCompound unitnbt = new NBTTagCompound();
                Writer.write(unitnbt, unit);
                nbt.setTag(UNIT_OBJECT, unitnbt);
            }
            if (kills != null) {
                NBTTagCompound killsnbt = new NBTTagCompound();
                Writer.write(killsnbt, kills);
                nbt.setTag(KILLS_OBJECT, killsnbt);
            }

            return nbt;

        }

        @Override
        public void setNBT(NBTTagCompound value) {
            this.nbt = value;
            this.mana = value.getFloat(MANA);
            this.energy = value.getFloat(ENERGY);
            this.level = value.getInteger(LEVEL);
            this.exp = value.getInteger(EXP);
            this.rarity = value.getInteger(RARITY);
            this.uuid = value.getString(UUID);
            this.name = value.getString(NAME);
            this.currentMapId = value.getInteger(CURRENT_MAP_ID);
            this.equipsChanged = value.getBoolean(EQUIPS_CHANGED);
            this.dmgByNonPlayers = value.getFloat(DMG_DONE_BY_NON_PLAYERS);

            NBTTagCompound object_nbt = (NBTTagCompound) this.nbt.getTag(UNIT_OBJECT);
            if (object_nbt != null) {
                unit = new Unit();
                Reader.read(object_nbt, unit);
            }

            NBTTagCompound kills_nbt = (NBTTagCompound) this.nbt.getTag(KILLS_OBJECT);
            if (kills_nbt != null) {
                kills = new PlayerMapKillsData();
                Reader.read(kills_nbt, kills);
            }

        }

 

Link to comment
Share on other sites

8 hours ago, diesieben07 said:

The problem is that you are trying to read data where there is none. This usually means you have a mismatch between the data you are sending and the data you are trying to read on the other side.

Again: Show your code.

Ok, Ive looked through the packets and noticed this one read and writed differently. The reader is missing Mobd saved once. Is this the problem?

Edited by 4sterism
Link to comment
Share on other sites

package com.robertx22.network;

import com.robertx22.mmorpg.Main;
import com.robertx22.uncommon.capability.EntityData;
import com.robertx22.uncommon.capability.EntityData.UnitData;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class EntityUnitPackage implements IMessage {

    public int id;
    public NBTTagCompound nbt;

    public EntityUnitPackage() {

    }

    public EntityUnitPackage(Entity entity) {
        this.id = entity.getEntityId();
        this.nbt = entity.getCapability(EntityData.Data, null).getNBT();
    }

    public EntityUnitPackage(Entity entity, UnitData data) {
        this.id = entity.getEntityId();
        this.nbt = data.getNBT();
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        nbt = ByteBufUtils.readTag(buf);
        id = nbt.getInteger("id");
    }

    @Override
    public void toBytes(ByteBuf buf) {
        nbt.setInteger("id", id);
        ByteBufUtils.writeTag(buf, nbt);

    }

    public static class Handler implements IMessageHandler<EntityUnitPackage, IMessage> {

        @Override
        public IMessage onMessage(EntityUnitPackage message, MessageContext ctx) {

            Runnable noteThread = new Runnable() {
                @Override
                public void run() {
                    try {

                        final EntityPlayer player = Main.proxy.getPlayerEntityFromContext(ctx);

                        if (player != null && player.world != null) {
                            Entity entity = player.world.getEntityByID(message.id);

                            EntityLivingBase en = (EntityLivingBase) entity;

                            if (en != null) {
                                en.getCapability(EntityData.Data, null).setNBT(message.nbt);

                            }

                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            };
            ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
            scheduler.schedule(noteThread, 1, TimeUnit.SECONDS);

            return null;
        }

    }
}
Edited by 4sterism
Link to comment
Share on other sites

its the nbt data associated with this packet. I deleted one entry and when it errored again, this time with was 31 instead of 32, so they're related. 

What I dont get is why readerIndex(31) + length(1) exceeds writerIndex(31). Where did that length 1 come from?

 

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

This is terrible in so many ways.

 

  1. It spawns a new thread every time. Spawning threads is very expensive.
  2. It does not properly dispose the created ExecutorService. Guava does this for you in this case through the finalize method (which is also just terrible, because it makes the GC work much harder to clean up this object), but it's still bad coding style.
  3. It's accessing MInecraft code from a completely random thread. Minecraft code must (99% of the time) only be accessed from it's main thread.

I'll leave out the fact that just dumping the whole capability NBT down the network is stupid (only sync what you need and don't use NBT for it if you can help it).

That error means that something is trying to read one byte (length 1), but there are 0 bytes available (because both readerIndex and writerIndex are 31). Read the Javadoc on ByteBuf, it explains how readerIndex and writerIndex work.

 

Show where you register your packets and where you send them.

I didn't write this code, but I'm willing to learn how to fix and clean it up.

As for where the code is registered.

MinecraftForge.EVENT_BUS.register(new PlayerUnitPackage());
MinecraftForge.EVENT_BUS.register(new EntityUnitPackage());
MinecraftForge.EVENT_BUS.register(new DamageNumberPackage());
MinecraftForge.EVENT_BUS.register(new ParticlePackage());
MinecraftForge.EVENT_BUS.register(new WorldPackage());
MinecraftForge.EVENT_BUS.register(new PacketAnimation());

Network.registerMessage(PlayerUnitPackage.Handler.class, PlayerUnitPackage.class, 0,
        Side.CLIENT);
Network.registerMessage(EntityUnitPackage.Handler.class, EntityUnitPackage.class, 1,
        Side.CLIENT);
Network.registerMessage(DamageNumberPackage.Handler.class, DamageNumberPackage.class, 2,
        Side.CLIENT);
Network.registerMessage(ParticlePackage.Handler.class, ParticlePackage.class, 3, Side.CLIENT);
Network.registerMessage(WorldPackage.Handler.class, WorldPackage.class, 4, Side.CLIENT);
Network.registerMessage(MessagePackage.Handler.class, MessagePackage.class, 5, Side.CLIENT);

 

@Mod.EventBusSubscriber
public class OnTrackEntity {

    @SubscribeEvent
    public static void onEntityTrack(PlayerEvent.StartTracking event) {

        Entity entity = event.getTarget();

        if (entity instanceof EntityLivingBase) {
            if (entity.isEntityEqual(event.getEntityPlayer()) == false) {
                if (entity.hasCapability(EntityData.Data, null)) {

                    Main.Network.sendTo(new EntityUnitPackage((EntityLivingBase) entity),
                            (EntityPlayerMP) event.getEntityPlayer());
                }

            }
        }

    }
}

 

/**
 * @return checks if it should be synced to clients. Clients currently only see health and status
 * effects
 */
private DirtyCheck getDirtyCheck() {

    DirtyCheck check = new DirtyCheck();

    check.hp = (int) MyStats.get(Health.GUID).Value;

    return check;
}

public void RecalculateStats(EntityLivingBase entity, UnitData data, int level,
                             IWorldData world) {

    data.setEquipsChanged(false);

    if (data.getUnit() == null) {
        data.setUnit(this, entity);
    }

    DirtyCheck old = getDirtyCheck();

    Unit copy = this.Clone();

    int tier = 0;
    if (world != null) {
        tier = world.getTier();
    }

    ClearStats();

    MobRarity rar = Rarities.Mobs.get(data.getRarity());

    float hpadded = this.getHpAdded(entity, rar, data);

    MyStats.get(Health.GUID).Flat += hpadded;


    if (entity instanceof EntityPlayer) {
        List<GearItemData> gears = PlayerStatUtils.getEquipsExcludingWeapon(entity); // slow
        boolean gearIsValid = this.isGearCombinationValid(gears, entity);

        ItemStack weapon = entity.getHeldItemMainhand();
        if (weapon != null) {
            GearItemData wep = Gear.Load(weapon);
            if (wep != null && wep.GetBaseGearType().slotType().equals(GearSlotType.Weapon))
                gears.add(wep);
        }

        ItemStack offhand = entity.getHeldItemOffhand();
        if (offhand != null) {
            GearItemData off = Gear.Load(offhand);
            if (off != null && off.GetBaseGearType().slotType().equals(GearSlotType.OffHand))
                gears.add(off);
        }

        PlayerStatUtils.AddPlayerBaseStats(data, this);

        if (gearIsValid) {
            PlayerStatUtils.CountWornSets(entity, gears, this);
            PlayerStatUtils.AddAllGearStats(entity, gears, this, level); // slow, but required
            PlayerStatUtils.AddAllSetStats(entity, this, level);
        }
    } else {
        MobStatUtils.AddMobcStats(data, data.getLevel(), entity);
        MobStatUtils.AddMobTierStats(this, tier);

    }

    CommonStatUtils.AddStatusEffectStats(this, level);
    CommonStatUtils.AddMapAffixStats(this, level);
    PlayerStatUtils.CalcStatConversionsAndTransfers(copy, this);
    PlayerStatUtils.CalcTraits(data);

    CalcStats(data);

    DirtyCheck newcheck = getDirtyCheck();

    if (old.isDirty(newcheck)) {
        Main.Network.sendToAllTracking(new EntityUnitPackage(entity, data), entity);
    }

}
Link to comment
Share on other sites

Thank you for taking your time. Ok, I will try to upload a repository. RecalculateStats is called int he same class and another class. That has a method called recalculateStats, that checks if the unit is null or if there is a need to recalc the stats. That method is called in a number of places.

Link to comment
Share on other sites

14 minutes ago, diesieben07 said:

Where is RecalculateStats called from?

In general, is it possible to post a Git repository of the mod?

https://github.com/ndrwln/Mine-and-Slash-modified

Its just open source code I modified so...

I also think the baubles jar is a forked version someone changed so that it would send an event when equipment changed. So that my mod could catch it and recalculate the stats. Its in the lib folder. The original implementation of the mod would not recalc stats when a bauble equip was changed -_-.

 

The crash doesnt occur when changing equipment, though. Sometimes we can go 40 minutes without a crash. Other times its constant crashing,

Edited by 4sterism
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Which monsters? I can't even fight the slimes in superflat, their attacks are one-hit kills and things like regen don't work.

I don't know whats causing the crashes exactly. And yh, I think I need to nerf slime dmg. We dont encounter lots of slimes. Regen happens every second. Ive never seen a problem with regen.

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Sorry, but I am not playing around for hours in game trying to get this to happen... You need to spend some time and isolate it.

Ok. I will do that. On server, fighting mosnters can usually cause crashes. Testing on client doesnt cause crashes though, which is telling.

Edited by 4sterism
Link to comment
Share on other sites

6 hours ago, diesieben07 said:

This is terrible in so many ways.

 

  1. It spawns a new thread every time. Spawning threads is very expensive.
  2. It does not properly dispose the created ExecutorService. Guava does this for you in this case through the finalize method (which is also just terrible, because it makes the GC work much harder to clean up this object), but it's still bad coding style.
  3. It's accessing MInecraft code from a completely random thread. Minecraft code must (99% of the time) only be accessed from it's main thread.

By the way, where should I read up on how to improve this for future reference?

Link to comment
Share on other sites

3 minutes ago, 4sterism said:

By the way, where should I read up on how to improve this for future reference?

You can look up how threading works in Java and the common design pattern when using threading.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Is this mod released somewhere? If so that's against my permission as i reserved all rights. I only allowed private use of modified code.

 

Also the 1.12.2 version has a crapton of my spaghetti code which is mostly ironed out in 1.14.4 as i spent months reworking most things. Yes, months to rework things, so i don't suggest you try fix.

 

Also sorry sieben for the problems.

 

 

 

Link to comment
Share on other sites

4 hours ago, robertx555 said:

Is this mod released somewhere? If so that's against my permission as i reserved all rights. I only allowed private use of modified code.

 

Also the 1.12.2 version has a crapton of my spaghetti code which is mostly ironed out in 1.14.4 as i spent months reworking most things. Yes, months to rework things, so i don't suggest you try fix.

 

Also sorry sieben for the problems.

 

 

 

Its not relased anywhere, its just for a group of small friends. I have no interest in releasing it anywhere.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When i try to launch Minecraft Java 1.20.1 forge with mods (82 mods),on start it loaded all mods,but at end Java just crashed.  p.s i allocated 8GB ram for minecraft and i didn't runned another instance.Log file pp.s I use ATlauncher   Environment: Organising filesystem [24/04/2024 23:40:08 PM] ATLauncher Version: 3.4.36.3 [11ae0b2334c236e93ee8128de980952b2a1b8900] [24/04/2024 23:40:08 PM] App Arguments: ["--install-method=aur","--no-launcher-update"] [24/04/2024 23:40:08 PM] JVM Arguments: ["-Dawt.useSystemAAFontSettings=on","-Dswing.aatext=true"] [24/04/2024 23:40:08 PM] Java Version: Java 22 (22) [24/04/2024 23:40:08 PM] Java Path: /usr/lib/jvm/java-22-openjdk [24/04/2024 23:40:08 PM] 64 Bit Java: true [24/04/2024 23:40:08 PM] RAM Available: 14931MB [24/04/2024 23:40:08 PM] Launcher Directory: **USERSDIR** [24/04/2024 23:40:08 PM] GPU: IvyBridge GT2 [HD Graphics 4000] (Intel Corporation (0x8086)) unknown 256MB VRAM [24/04/2024 23:40:08 PM] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz 4 cores/8 threads [24/04/2024 23:40:08 PM] Operating System: EndeavourOS (unknown (unknown) build 6.8.7-arch1-1) [24/04/2024 23:40:08 PM] Bitness: 64 [24/04/2024 23:40:08 PM] Uptime: 15889 [24/04/2024 23:40:08 PM] Manufacturer: GNU/Linux
    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.