mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.97k stars 261 forks source link

Huge memory leaks TempBuffer.RenderTexture using softmask #109

Closed novavision closed 3 years ago

novavision commented 3 years ago

Describe the bug Using SoftMasks in multiple screens in the game cause 150mb memory leak creating up to 50 render textures.

To Reproduce Steps to reproduce the behavior: Create multiple scroll views with 1-2 softmask images in each scrollable item.

Expected behavior SoftMask not spam the RenderTextures for each UI image with this component attached

Screenshots

Memory Profiler

Environment (please complete the following information):

Additional context Add any other context about the problem here.

mob-sakai commented 3 years ago

@novavision Thank you for your reporting!

evgeny-detkov commented 3 years ago

Hey! We also have this problem. Please resolve the issue as soon as possible. Thank!

profiler

mob-sakai commented 3 years ago

@evgeny-detkov @novavision Could you please attach a minimal project (included Assets, Packages and ProjectSettings directories) that reproduces the issue?

evgeny-detkov commented 3 years ago

@mob-sakai LINK to test project

image

mob-sakai commented 3 years ago

@evgeny-detkov Thanks!

mob-sakai commented 3 years ago

@evgeny-detkov Create a parent SoftMask to share a single RenderTexture. Set up as follows:

  1. Select Canvas/Scroll View/Viewport game object and convert Mask component to SoftMask component from the context menu (Convert to SoftMask).
  2. Fix 2 warnings.
  3. Select Canvas/Scroll View/Viewport/Content/GameObject ~ GameObject(97) game objects and disable Ignore Parent and Part Of Parent.
  4. That's all. :tada:

Fixed test project

soft_mask_testject.zip

novavision commented 3 years ago

Thanks for explanation, I tried adapt your test scene to my hierarchy and it seems working fine. But I got question regarding to my case (I think it's pretty common UI structure):

I got 20+ screens, some of them has ScrollRect (~10) with SoftMask used in their children. Some screens has >1 ScrollRect. In terms of memory optimization, using your solution above, it's better to attach the SoftMask to the parent (screen object). Even in this case I will have ~10 RenderTexture in buffer. What if I add 'SoftMaskit to most parent object? Like mainCanvas`? Will it negatively affect to the performance?

mob-sakai commented 3 years ago

Could you please attach a minimal project (included Assets, Packages and ProjectSettings directories) that reproduces the issue?

novavision commented 3 years ago

It's not an issue, it's a question, related to buffered RenderTexture optimization.

mob-sakai commented 3 years ago

If the SoftMask buffers are the same size (= Down Sampling Rate), they will be recycled.