Jump to content

[1.8] IMessage crashes


Mistram

Recommended Posts

I created a Networkchannel, that is working just fine, and a IMessage and its Handler.

I am triing to send an integer over the channel, shorts are working no problem. The message is registered, but if I try to send it I get a strange exception.

 

 

 

[08:38:56] [Netty Local Client IO #0/ERROR] [FML]: There was a critical exception handling a packet on channel TriamChannel

io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Varint length is between 1 and 5, not 16

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.15.Final]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) ~[DefaultChannelHandlerContext.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) ~[DefaultChannelHandlerContext.class:4.0.15.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:4.0.15.Final]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:4.0.15.Final]

at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:88) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:144) [NetworkManager.class:?]

at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:469) [NetworkManager.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:363) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:230) [NetworkDispatcher.class:?]

at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:49) [NetworkDispatcher.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103) [simpleChannelInboundHandler.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) [DefaultChannelHandlerContext.class:4.0.15.Final]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) [DefaultChannelHandlerContext.class:4.0.15.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:4.0.15.Final]

at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:312) [LocalChannel.class:4.0.15.Final]

at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:44) [LocalChannel.class:4.0.15.Final]

at io.netty.channel.local.LocalChannel$6.run(LocalChannel.java:298) [LocalChannel$6.class:4.0.15.Final]

at io.netty.channel.local.LocalEventLoop.run(LocalEventLoop.java:33) [LocalEventLoop.class:4.0.15.Final]

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [singleThreadEventExecutor$2.class:4.0.15.Final]

at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]

 

 

 

 

Message and Handler class

 

public class ActualEnergyMessage implements IMessage{

private int actualEnergy;

public ActualEnergyMessage() {

}

public ActualEnergyMessage(int actualEnergy) {
	this.actualEnergy = actualEnergy;
}

@Override
public void fromBytes(ByteBuf buf) {
	actualEnergy = ByteBufUtils.readVarInt(buf, 16);

}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeVarInt(buf, actualEnergy, 16);

}


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

	@Override
	public IMessage onMessage(ActualEnergyMessage message,
			MessageContext ctx) {
		((ExtendedPlayer)(Minecraft.getMinecraft().thePlayer.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME))).setActualEnergy(message.actualEnergy);
		return null;
	}

}

}

Link to comment
Share on other sites

It literally says in the top line...

 

[08:38:56] [Netty Local Client IO #0/ERROR] [FML]: There was a critical exception handling a packet on channel TriamChannel
io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Varint length is between 1 and 5, not 16

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Link to comment
Share on other sites

Network messages are hard to get right in 1.8 because of multithreading.

 

This guide might help

http://greyminecraftcoder.blogspot.com.au/2015/01/the-client-server-division.html

especially

http://greyminecraftcoder.blogspot.com.au/2015/01/client-server-communication-using-your.html

and

http://greyminecraftcoder.blogspot.com.au/2015/01/thread-safety-with-network-messages.html

 

Also this tutorial project which has a working example of network messages (MBE60)

https://github.com/TheGreyGhost/MinecraftByExample

 

-TGG

 

Link to comment
Share on other sites

So. Just so I dont get this wrong.

The important part is that I queue up the processing of the message to the queue from minecraft

  minecraft.addScheduledTask(new Runnable()
    {
      public void run() {
        processMessage(worldClient, message);
      }
    });

Right?

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



×
×
  • Create New...

Important Information

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