TEMPORARY fix for chunk memory leaks

This commit is contained in:
Camotoy 2023-04-24 23:48:05 -04:00
parent abba88112a
commit b66088e434
2 changed files with 9 additions and 3 deletions

View File

@ -105,6 +105,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
int maxBedrockSectionY = (bedrockDimension.height() >> 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<Clientbo
for (NbtMap blockEntity : bedrockBlockEntities) {
nbtStream.writeTag(blockEntity);
}
byteBuf.retain();
payload = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(payload);
} catch (IOException e) {
session.getGeyser().getLogger().error("IO error while encoding chunk", e);
return;
@ -362,7 +364,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
levelChunkPacket.setCachingEnabled(false);
levelChunkPacket.setChunkX(packet.getX());
levelChunkPacket.setChunkZ(packet.getZ());
levelChunkPacket.setData(byteBuf);
levelChunkPacket.setData(Unpooled.wrappedBuffer(payload));
session.sendUpstreamPacket(levelChunkPacket);
if (!lecterns.isEmpty()) {

View File

@ -175,6 +175,7 @@ public class ChunkUtils {
BedrockDimension bedrockDimension = session.getChunkCache().getBedrockDimension();
int bedrockSubChunkCount = bedrockDimension.height() >> 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 {