Jump to content

[1.7.2] Potential Memory Leak


TLHPoE

Recommended Posts

I'm getting this in my console:

[09:55:14] [server thread/ERROR] [FML]: Detected ongoing potential memory leak. 100 packets have leaked. Top offenders
[09:55:14] [server thread/ERROR] [FML]: 	 ttm : 100

 

I'm partially worried, because this packet is from the client to the server, and is gonna be sent a lot.

 

Packet:

package ttm.network;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;

public class PacketMessage extends AbstractPacket {
public int msgID;

public PacketMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public PacketMessage() {
	this(0);
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	buffer.writeInt(msgID);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	msgID = buffer.readInt();
}

@Override
public void handleClientSide(EntityPlayer player) {
}

@Override
public void handleServerSide(EntityPlayer player) {
	switch(msgID) {
	case Reference.PacketMessages.JUMP: {
		ForgeHooks.onLivingJump(player);
		break;
	}
	}
}
}

 

Should I be worried about this?

Kain

Link to comment
Share on other sites

Is your packet system based on this tutorial?  http://www.minecraftforge.net/wiki/Netty_Packet_Handling

 

You'll see that there is now a warning on that tutorial saying it creates memory leaks and should not be used

 

Instead you need to use the new SimpleNetworkWrapper system: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I've run into a problem.

 

Whenever I send the message to the server, it never arrives. It only writes to the byte buffer.

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class SimpleServerMessage extends AbstractMessage {
public int msgID;

public SimpleServerMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public SimpleServerMessage() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(msgID);
}

@Override
public void fromBytes(ByteBuf buf) {
	msgID = buf.readInt();
}

public static class Handler implements IMessageHandler<SimpleServerMessage, IMessage> {
	public IMessage onMessage(SimpleServerMessage message, MessageContext ctx) {
		switch(message.msgID) {
		case Reference.PacketMessages.JUMP: {
			ForgeHooks.onLivingJump(ctx.getServerHandler().playerEntity);
			break;
		}
		}

		return null;
	}
}
}

 

Basic Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

Link to comment
Share on other sites

Ok, I only had the IDs because that message class was only for short messages.

 

None of my other messages are being received either.

 

Mod:

package ttm;

import static ttm.Reference.ID;
import static ttm.Reference.NAME;
import static ttm.Reference.VERSION;
import ttm.handler.GuiHandler;
import ttm.network.MessageJump;
import ttm.network.MessageOpenGui;
import ttm.network.MessageQuickStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

@Mod(name = NAME, modid = ID, version = VERSION)
public class TtM {
@Instance(ID)
public static TtM instance;
@SidedProxy(serverSide = ID + ".ServerProxy", clientSide = ID + ".ClientProxy")
public static ServerProxy proxy;

public static GuiHandler guiHandler = new GuiHandler();
public static SimpleNetworkWrapper networkChannel;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	NetworkRegistry.INSTANCE.registerGuiHandler(this, guiHandler);
	networkChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TtM");
	loadPackets();

	proxy.loadServer();
	proxy.loadClient();
}

public void loadPackets() {
	networkChannel.registerMessage(MessageJump.Handler.class, MessageJump.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageOpenGui.Handler.class, MessageOpenGui.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageQuickStack.Handler.class, MessageQuickStack.class, 0, Side.SERVER);
}
}

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class MessageOpenGui extends BasicMessage {
public int guiID;

public MessageOpenGui(int guiID) {
	super();
	this.guiID = guiID;
}

public MessageOpenGui() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(guiID);

	System.err.println("HI2");
}

@Override
public void fromBytes(ByteBuf buf) {
	guiID = buf.readInt();

	System.err.println("HI");
}

public static class Handler implements IMessageHandler<MessageOpenGui, IMessage> {
	public IMessage onMessage(MessageOpenGui message, MessageContext ctx) {
		EntityPlayer player = ctx.getServerHandler().playerEntity;

		player.openGui(TtM.instance, message.guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);

		return null;
	}
}
}

 

BasicMessage:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

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

    • Here's the newest crash: https://pastebin.com/mumDeWzW Seems to have something to do with JEI Also delete that server file? Also the newest log: https://pastebin.com/ATH8dbWc
    • Recently started to attempt 1.20.1 modding, in registering idle, walk and attack animations in the mob entity class i've run into two issues:   a) idle and walk animations seem to play simultaneously  + the mob itself does not seem to walk private static final EntityDataAccessor<Boolean> ATTACKING = SynchedEntityData.defineId(MugaEntity.class, EntityDataSerializers.BOOLEAN); public MugaEntity(EntityType<? extends Monster > pEntityType, Level pLevel) { super(pEntityType, pLevel); } public final AnimationState idleAnimationState = new AnimationState(); private int idleAnimationTimeout = 1; public final AnimationState attackAnimationState = new AnimationState(); public int attackAnimationTimeout = 0; @Override public void tick() { super.tick(); if(this.level().isClientSide()) { setupAnimationStates(); } } private void setupAnimationStates () { if(this.idleAnimationTimeout <= 0) { this.idleAnimationTimeout = this.random.nextInt(30) + 60; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } if (this.isAttacking() && attackAnimationTimeout <= 0 ) { attackAnimationTimeout = 20; attackAnimationState.start(this.tickCount); } else { --this.attackAnimationTimeout; } if(this.isAttacking()) { attackAnimationState.stop(); } } @Override protected void updateWalkAnimation(float pPartialTick) { float f; if(this.getPose() == Pose.STANDING) { f=Math.min(pPartialTick * 3.0F, 1.0F); } else { f= 0.0F; } this.walkAnimation.update(f, 0.2F); } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(ATTACKING, false); } public void setAttacking(boolean attacking) { this.entityData.set(ATTACKING, attacking); } public boolean isAttacking() { return this.entityData.get(ATTACKING); } b) the attack animation is never played on attack, despite being registered  @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.animateWalk(ModAnimationDefinitions.MUGA_WALKING, limbSwing, limbSwingAmount, 1f, 1f ); this.animate(((MugaEntity)entity).idleAnimationState, ModAnimationDefinitions.MUGA_IDLE, ageInTicks, 1f); this.animate(((MugaEntity)entity).attackAnimationState, ModAnimationDefinitions.MUGA_ATTACK, ageInTicks, 1f); }
    • Maybe there are some more broken files - check the new crash-report - the file name is mentioned in the first lines   If it is another crash, add it here
    • Thanks. Found and deleted it, but it doesn't change anything. When joining a new file is created, the screen freezes/ does not respond in typical manner and I have to close it then. I deleted it in curseforge>minecraft>instances>Modpack>saves>World>serverconfig Should I have deleted it anywhere else?
  • Topics

×
×
  • Create New...

Important Information

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