playcanvas / playcanvas/engine

Legacy cubemap causes memory (VRAM) leak

Open
#7,882 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Reproduction project: https://playcanvas.com/editor/scene/2290736

Engine Version
2.10.3 & 1.77.0

Steps to reproduce:
  1. Enable the profiler and lanch
  2. Click either the "loopUnloadMaterialWithCubeMap" or "loopUnloadMaterialWithCubeMapDds" button
  3. Observe that "Textures Other" in VRAM continuously increases until the browser crashes
Background:

I encountered an issue where "Textures Other" in VRAM was abnormally large in a project. After investigation, I found that it was caused by multiple uses of a legacy cubeMap. Disabling the "Generate legacy cubemap" option resolved the memory issue but introduced unacceptable visual differences. Strangely, re-enabling the option resulted in a visual that was different from both previous states.

In the reproduction project, you can observe three cubemaps with different behaviors:

  • HDR01 (original)
  • HDR01.png (with "Generate legacy cubemap" disabled)
  • HDR01.dds (with "Generate legacy cubemap" enabled again)
Root cause:

Each time a material containing a legacy cubemap is loaded, it executes pc.EnvLighting.generatePrefilteredAtlas. The objects created in this method are not cached or destroyed, leading to memory leaks.

Current workaround:

I've mitigated the issue by monkey-patching pc.EnvLighting.generatePrefilteredAtlas to cache the created objects, reducing memory usage and preventing leaks.

Requests:
  1. Fix the memory leak caused by legacy cubemaps
  2. Ensure consistent visual whether "Generate legacy cubemap" is enabled or not

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at pc.EnvLighting.generatePrefilteredAtlas and reproduce the issue with the linked project using the profiler and either loopUnloadMaterialWithCubeMap button. Trace the objects created for legacy cubemaps and verify their reuse or cleanup. Done means repeated loading no longer increases Textures Other until the browser crashes, while the legacy-cubemap visuals remain consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.