Skip to content

Commit

Permalink
Fix PlayerHeadTexture memory leaks (#4196)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Nov 10, 2023
1 parent 7b5a81d commit d9cd99c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import org.lwjgl.BufferUtils;
import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

Expand Down Expand Up @@ -65,8 +67,8 @@ public PlayerHeadTexture(String url) {
}

public PlayerHeadTexture() {
try {
ByteBuffer data = TextureUtil.readResource(mc.getResourceManager().getResource(new MeteorIdentifier("textures/steve.png")).get().getInputStream());
try (InputStream inputStream = mc.getResourceManager().getResource(new MeteorIdentifier("textures/steve.png")).get().getInputStream()) {
ByteBuffer data = TextureUtil.readResource(inputStream);
data.rewind();

try (MemoryStack stack = MemoryStack.stackPush()) {
Expand All @@ -78,6 +80,7 @@ public PlayerHeadTexture() {
upload(image);
STBImage.stbi_image_free(image);
}
MemoryUtil.memFree(data);
}
catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit d9cd99c

Please sign in to comment.