Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SDK's LightSource texture memory leak #498

Open
pravusjif opened this issue Mar 10, 2025 · 0 comments
Open

SDK's LightSource texture memory leak #498

pravusjif opened this issue Mar 10, 2025 · 0 comments
Labels
2-medium Important issues we must fix, but not as important as high! bug Something isn't working unity

Comments

@pravusjif
Copy link
Member

pravusjif commented Mar 10, 2025

If any LightSource that uses a shadowmask texture is later-on modified on any of its properties, the texture promise gets re-created and leaks memory heavily.

test-scene that showcases the problem by just running the scene and being inside it: https://github.com/decentraland-scenes/light-memory-leak-test

There's a different problem with LightSource and raw texture compression (only enabled on MacOS) in which during local scene development (no asset bundles) shadow mask textures are failing to be compressed in runtime and so they don't work during Local Scene Development, so there's no memory leak in that case due to that other bug.

The shadowmask has to be visible for it to leak, like:

Lightsource-2.mp4

First attempt at fixing the issue is not enough and should be continued: decentraland/unity-explorer#3492.

Ideas for solution (the texture asset promise is being handled in a wrong), we should:

  • Either:
    • Use TryGetResult() instead of TryConsume() at ResolveTexturePromise() to actually keep the used promise at lightSourceComponent.TextureMaskPromise to be compared inside TryCreateGetTexturePromise() based on its loadingIntention or similar (and avoid returning false at if (TextureComponentUtils.Equals(ref textureComponentValue, ref promise)) which makes it create a new promise for the texture that was already loaded but consumed...). That would be similar as what it's being done for Material systems when keeping the promise at CreateMaterialSystemBase.
    • Keep using TryConsume() but storing the loadingIntention or the file hash in a new prop at LightSourceComponent to be compared at TryCreateGetTexturePromise() and avoid re-creating the promise when dealing with the same loading intention.
  • Improve the promise cleanup to use ForgetLoading(World) and Consume(World) depending on the previous suggested approaches selection
@pravusjif pravusjif added the bug Something isn't working label Mar 10, 2025
@pravusjif pravusjif changed the title SDK's LightSource heavy memory leak SDK's LightSource texture memory leak Mar 10, 2025
@nearnshaw nearnshaw added unity 2-medium Important issues we must fix, but not as important as high! labels Mar 10, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
2-medium Important issues we must fix, but not as important as high! bug Something isn't working unity
Projects
Status: Todo
Status: Todo
Development

No branches or pull requests

2 participants