Skip to content

Commit

Permalink
Fix memory leaks in RenderUtils.java (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToonSpin authored and sakura-ryoko committed Feb 25, 2025
1 parent 90b8b02 commit 1c73cc4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/fi/dy/masa/malilib/render/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -881,28 +881,31 @@ public static void drawTextPlate(List<String> text, double x, double y, double z
}

Matrix4f modelMatrix = new Matrix4f();
BufferAllocator byteBufferBuilder = new BufferAllocator(RenderLayer.DEFAULT_BUFFER_SIZE);
modelMatrix.identity();

BufferAllocator allocator = new BufferAllocator(RenderLayer.DEFAULT_BUFFER_SIZE);

for (String line : text)
{
if (disableDepth)
{
//RenderSystem.depthMask(false);
RenderSystem.disableDepthTest();
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(byteBufferBuilder);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(allocator);
textRenderer.draw(line, -strLenHalf, textY, 0x20000000 | (textColor & 0xFFFFFF), false, modelMatrix, immediate, TextRenderer.TextLayerType.SEE_THROUGH, 0, 15728880);
immediate.draw();
RenderSystem.enableDepthTest();
//RenderSystem.depthMask(true);
}

VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(byteBufferBuilder);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(allocator);
textRenderer.draw(line, -strLenHalf, textY, textColor, false, modelMatrix, immediate, TextRenderer.TextLayerType.SEE_THROUGH, 0, 15728880);
immediate.draw();
textY += textRenderer.fontHeight;
}

allocator.close();

if (disableDepth == false)
{
RenderSystem.polygonOffset(0f, 0f);
Expand Down Expand Up @@ -1192,7 +1195,8 @@ public static void renderMapPreview(ItemStack stack, int x, int y, int dimension
x1 += 8;
y1 += 8;
z = 310;
VertexConsumerProvider.Immediate consumer = VertexConsumerProvider.immediate(new BufferAllocator(RenderLayer.DEFAULT_BUFFER_SIZE));
BufferAllocator allocator = new BufferAllocator(RenderLayer.DEFAULT_BUFFER_SIZE);
VertexConsumerProvider.Immediate consumer = VertexConsumerProvider.immediate(allocator);
double scale = (double) (dimensions - 16) / 128.0D;

// TODO -- MapRenderer still uses MatrixStack
Expand All @@ -1203,6 +1207,7 @@ public static void renderMapPreview(ItemStack stack, int x, int y, int dimension
mc().gameRenderer.getMapRenderer().draw(matrixStack, consumer, mapId, mapState, false, 0xF000F0);
consumer.draw();
matrixStack.pop();
allocator.close();
}
}
}
Expand Down Expand Up @@ -1353,6 +1358,10 @@ public static void renderNbtItemsPreview(ItemStack stackIn, @Nonnull NbtCompound
{
if (InventoryUtils.hasNbtItems(itemsTag))
{
if (mc().world == null)
{
return;
}
DefaultedList<ItemStack> items = InventoryUtils.getNbtItems(itemsTag, -1, mc().world.getRegistryManager());

if (items.size() == 0)
Expand Down

0 comments on commit 1c73cc4

Please sign in to comment.