mojira.dev
MC-298898

TextureAtlas leaks textures after resource reload

Texture atlases are leaking textures on every resource reload since 1.21.5 (specifically since 25w07a where TextureAtlas#upload() switched from calling TextureUtil.prepareImage() to this.texture = new GpuTexture(...) - replaced by a GpuDevice#createTexture() call in a later snapshot).
Before that snapshot, each atlas created a GL texture exactly once by virtue of the first call to AbstractTexture#getId() calling GL11.glGenTextures() (indirection omitted) and subsequent calls returning the previously allocated ID and atlas uploads only (re)configuring texture parameters and calling GL11.glTexImage2D() for every active mip level.
Since the 25w07a snapshot, every atlas upload allocates a new GL texture, assigns it to AbstractTexture#texture and discards the old GpuTexture without further action. The only time GpuTexture#close() is called from a TextureAtlas is when the TextureManager holding the atlas is close()ed. This means that the previous GpuTexture backing the atlas stays allocated (since 1.21.6 the same applies to the GpuTextureView) and continues consuming VRAM.
As an extreme case, using a 512*512 resource pack which blows the block atlas up to a size of 16384*16384 pixels, the VRAM use of the game can be observed to increase by ~1.3 GB after every resource reload. If TextureAtlas#upload() is modified to close the previous texture and texture view first, then VRAM usage does not change after a resource reload.

Environment

Minecraft Version: 1.21.6
Operating System: Windows 10 (amd64) version 10.0
Java Version: 21.0.7, Microsoft
Memory: 32 GB
CPU: 13th Gen Intel(R) Core(TM) i9-13900K
GPU: NVIDIA GeForce RTX 4080

Linked issues

Comments 0

No comments.

XFactHD

Filip Randenbäck

Plausible

Platform

Important

Textures and models

1.21.6

1.21.7 Release Candidate 1

Retrieved