Jump to content

Recommended Posts

Posted

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?

Posted (edited)

The problem is that I dont know what the problem is in the first place. Can you explain to me what this error means exactly and where I should be looking/ what problem I am facing?

Edited by 4sterism
Posted
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.

Posted
4 hours ago, Draco18s said:

Question:

Did you write your own mod

or

Do you just run a modded server?

Its a mod that I was changing; I have access to the source code and heavily modified it.

Posted
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.

Posted
 @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);
            }

        }

 

Posted (edited)
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
Posted (edited)
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
Posted

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?

 

Posted
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);
    }

}
Posted
4 minutes ago, diesieben07 said:

Is RecalculateStats ever called not on the main thread?

I dont understand what Im being asked, and googling just describes errors.

Posted

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.

Posted (edited)
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
Posted
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.

Posted (edited)
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
Posted
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?

Posted
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.

 

 

Posted

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.

 

 

 

Posted
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.

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



×
×
  • Create New...

Important Information

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