Posted November 2, 20159 yr Hi, I got a little problem, where i get a crash on the client side when i send a packet form the server to all clients. If the server is a LAN server than the "client" where the server is opened it dont crash only for other clients. Register in preInit(ID 0 isnt duplicated): snw.registerMessage(MusicBoxMessageHandler.class, MusicBoxMessage.class, 0, Side.CLIENT); Packet: public class MusicBoxMessage implements IMessage { int x, y, z; int track; int volume; boolean repeat; boolean isAmb; public MusicBoxMessage(){ } public MusicBoxMessage(BlockPos pos, int track, int volume, boolean repeat, boolean isAmb){ this.x = pos.getX(); this.y = pos.getY(); this.z = pos.getZ(); this.track = track; this.volume = volume; this.repeat = repeat; this.isAmb = isAmb; } @Override public void toBytes(ByteBuf buf){ buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); buf.writeInt(track); buf.writeInt(volume); buf.writeBoolean(repeat); buf.writeBoolean(isAmb); } @Override public void fromBytes(ByteBuf buf){ this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.track = buf.readInt(); this.volume = buf.readInt(); this.repeat = buf.readBoolean(); this.isAmb = buf.readBoolean(); } } Pakcet handler: public class MusicBoxMessageHandler implements IMessageHandler<MusicBoxMessage, IMessage> { public MusicBoxMessageHandler(){ } @Override public IMessage onMessage(final MusicBoxMessage message, final MessageContext ctx) { IThreadListener threadlistener = Minecraft.getMinecraft(); threadlistener.addScheduledTask(new Runnable(){ public void run(){ BlockPos pos = new BlockPos(message.x, message.y, message.z); AmnesiaMusicBox.proxy.playMusic(pos, message.track, message.volume, message.repeat, message.isAmb); } }); return null; } } Sending the packet: @Override public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock){ if(!worldIn.isRemote){ TileEntityMusicBox custombox = ((TileEntityMusicBox)worldIn.getTileEntity(pos)); if(worldIn.isBlockIndirectlyGettingPowered(pos) > 0 && !(Boolean)state.getValue(POWERED)){ worldIn.setBlockState(pos, state.withProperty(POWERED, true)); AmnesiaMusicBox.snw.sendToAll(new MusicBoxMessage(pos, custombox.track, custombox.volume, custombox.repeat, custombox.isAmb)); } else if(worldIn.isBlockIndirectlyGettingPowered(pos) == 0 && (Boolean)state.getValue(POWERED)){ worldIn.setBlockState(pos, state.withProperty(POWERED, false)); } } } Crash: FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(21) + length(1) exceeds writerIndex(21): SlicedByteBuf(ridx: 21, widx: 21, cap: 21/21, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 22, cap: 22)) 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(Unknown Source) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.channelRead0(Unknown Source) [NetworkManager.class:?] at net.minecraft.network.NetworkManager.channelRead0(Unknown Source) [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(Unknown Source) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(Unknown Source) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(Unknown Source) [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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.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.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:149) [ReadTimeoutHandler.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.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:132) [AbstractNioByteChannel$NioByteUnsafe.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485) [NioEventLoop.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452) [NioEventLoop.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346) [NioEventLoop.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_60] Caused by: java.lang.IndexOutOfBoundsException: readerIndex(21) + length(1) exceeds writerIndex(21): SlicedByteBuf(ridx: 21, widx: 21, cap: 21/21, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 22, cap: 22)) at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1161) ~[AbstractByteBuf.class:4.0.15.Final] at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:563) ~[AbstractByteBuf.class:4.0.15.Final] at io.netty.buffer.AbstractByteBuf.readBoolean(AbstractByteBuf.java:572) ~[AbstractByteBuf.class:4.0.15.Final] at com.fluffy2.amnesiamusicbox.pakets.MusicBoxMessage.fromBytes(MusicBoxMessage.java:47) ~[MusicBoxMessage.class:?] at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(Unknown Source) ~[simpleIndexedCodec.class:?] at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(Unknown Source) ~[simpleIndexedCodec.class:?] at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(Unknown Source) ~[FMLIndexedMessageToMessageCodec.class:?] at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(Unknown Source) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.15.Final] ... 39 more It pointing to this line: this.isAmb = buf.readBoolean(); I dont know what the hell is the problem with that, i checked the order of writing and reading, i checked and the data is both correct on client and server. I dont know simply what it wants. Thanks for helping!
November 2, 20159 yr Hmmm, it looks correct to me. I'm wondering if maybe one of the values is null when you're trying to construct the message? I'd add some console or logger statements in the toBytes and fromBytes to confirm that the values are what you expect. Normally I expected to find that you had mixed up the order, or mixed up the types, or registered multiple with same ID, or forgot to make it threaded, but it seems that you've covered all that. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
November 2, 20159 yr Author Okay, i did a few system prints. The data is correct, on toByte and fromByte. I also noticed that the crash happends randomly. If i send the packet i got a 90% chance of crashing. Sometimes it goes througth right. I also checked out that i remove all the fields, and send an empty packet. The toByte and fromByte can be empty, and the onMessage can be empty also, but i got a crash like this. FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException 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(Unknown Source) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.channelRead0(Unknown Source) [NetworkManager.class:?] at net.minecraft.network.NetworkManager.channelRead0(Unknown Source) [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(Unknown Source) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(Unknown Source) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(Unknown Source) [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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [byteToMessageDecoder.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.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.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.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:149) [ReadTimeoutHandler.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.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:132) [AbstractNioByteChannel$NioByteUnsafe.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485) [NioEventLoop.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452) [NioEventLoop.class:4.0.15.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346) [NioEventLoop.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_60] Caused by: java.lang.IndexOutOfBoundsException at io.netty.buffer.EmptyByteBuf.readByte(EmptyByteBuf.java:440) ~[EmptyByteBuf.class:4.0.15.Final] at net.minecraft.network.PacketBuffer.readByte(Unknown Source) ~[PacketBuffer.class:?] at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(Unknown Source) ~[FMLIndexedMessageToMessageCodec.class:?] at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(Unknown Source) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.15.Final] ... 39 more
November 3, 20159 yr Strange... What does your initialization of the snw field look like? Check out my tutorials here: http://jabelarminecraft.blogspot.com/
November 3, 20159 yr Author On the main class: public static SimpleNetworkWrapper snw; .... @EventHandler public void preInit(FMLPreInitializationEvent event){ //Pakets snw = NetworkRegistry.INSTANCE.newSimpleChannel(AmnesiaMusicBox.ModID); snw.registerMessage(MusicBoxMessageHandler.class, MusicBoxMessage.class, 0, Side.CLIENT); snw.registerMessage(LoadFilesMessageHandler.class, LoadFilesMessageHandler.class, 1, Side.CLIENT); snw.registerMessage(MusicBoxGuiMessageHandler.class, MusicBoxGuiMessageHandler.class, 2, Side.SERVER); } The mod id is: AmnesiaMusicBox wich isnt more than 20 character.
November 3, 20159 yr On the main class: public static SimpleNetworkWrapper snw; .... @EventHandler public void preInit(FMLPreInitializationEvent event){ //Pakets snw = NetworkRegistry.INSTANCE.newSimpleChannel(AmnesiaMusicBox.ModID); snw.registerMessage(MusicBoxMessageHandler.class, MusicBoxMessage.class, 0, Side.CLIENT); snw.registerMessage(LoadFilesMessageHandler.class, LoadFilesMessageHandler.class, 1, Side.CLIENT); snw.registerMessage(MusicBoxGuiMessageHandler.class, MusicBoxGuiMessageHandler.class, 2, Side.SERVER); } The mod id is: AmnesiaMusicBox wich isnt more than 20 character. You should probably shorten it, just to be safe. For example, your mod ID could be "amb", and your channel could be MODID+"net". Also, with mod ID, you should keep it all lowercase. This is the domain for your resource locations, and keeping it in convention with Minecraft's domain is better.
November 3, 20159 yr Author Okay, i tried "ambnet", no luck. I make a new packet that is empty, it has the default constructor and no info inside. It still crash. I think that .sendToAll() is the problem, because in my previous 1.8 modding i got this kind of crashes as well, when i used sendToAll, but i replaced it with the entity tracked packet sending and it fixed all, yet i didnt know this bug. Just to prove even more, i got another mod, wich works perfectly it also has a sendToAll method and it also crashes. All the other packets .sendTo and .sendToServer works without crash. And they are made the same way like the problematic ones. So i think .sendToAll is broken
November 3, 20159 yr Interesting. However, I use sendToAll() in all my 1.8 mods and haven't seen such a crash before. But of course that doesn't prove there isn't some bug. Is it possible your netty code is old or buggy? Have you tried re-building your workspace? Also, does it happen on other computers as well? Check out my tutorials here: http://jabelarminecraft.blogspot.com/
November 3, 20159 yr Author Yeah, mayebe. I gonna update forge, do a clean workspace install and make a dummy mod just for that.
November 5, 20159 yr Author Okay, it start to piss me off! I made a new project called "dummymod", just because of that. And it still crashes, it dosent matter where is the packet sent from(block or item action), it dosent matter where IMessage and IMessageHandler is implemenet in 1 class. It always gonna crash, yet a made a full clean installation of the latest forge, updated java, deleted .gradle. So yeah, the bug is in Forge for sure now.
November 5, 20159 yr Author So, good news and bad news. Good is it works on dedicated servers. I opened a server and 2 clients with 2 different login details. It worked. Bad news is, if i open 2 client and open a LAN the crash happends. So dedicated server works, LAN crashes. Mayebe its something up with that i cant debug 2 clients with LAN?
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.