From b66088e43479040399461aa71d5a5d2d0aa70a71 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:48:05 -0400 Subject: [PATCH] TEMPORARY fix for chunk memory leaks --- .../java/level/JavaLevelChunkWithLightTranslator.java | 6 ++++-- core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java index 5f25ff58e..fd33ca1df 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java @@ -105,6 +105,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator> 4) - 1; int sectionCount; + byte[] payload; ByteBuf byteBuf = null; GeyserChunkSection[] sections = new GeyserChunkSection[javaChunks.length - (yOffset + (bedrockDimension.minY() >> 4))]; @@ -347,7 +348,8 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator> 4; + byte[] payload; // Allocate output buffer ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(ChunkUtils.EMPTY_BIOME_DATA.length * bedrockSubChunkCount + 1); // Consists only of biome data and border blocks try { @@ -185,11 +186,14 @@ public class ChunkUtils { byteBuf.writeByte(0); // Border blocks - Edu edition only + payload = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(payload); + LevelChunkPacket data = new LevelChunkPacket(); data.setChunkX(chunkX); data.setChunkZ(chunkZ); data.setSubChunksLength(0); - data.setData(byteBuf.retain()); + data.setData(Unpooled.wrappedBuffer(payload)); data.setCachingEnabled(false); session.sendUpstreamPacket(data); } finally {