Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Unity 2022.3.2f1 URP - Render Texture from Camera is crashing the application

Discussion in 'Universal Render Pipeline' started by JamesSozoLabs, Jun 27, 2023.

  1. JamesSozoLabs

    JamesSozoLabs

    Joined:
    Jan 10, 2022
    Posts:
    13
    Hey,

    We're busy developing a VR application for the Meta Quest 2.
    So we recently upgraded a project of ours to Unity 2022.3.2f1 URP + Android from Unity 2021.3 URP + Android.

    We have a scene that passed QA a while back and had no issues in Unity 2021.
    But after we upgraded this specific scene started crashing out of the blue.
    After disabling game objects, we've narrowed it down exactly to the Camera that is outputting to a Render Texture, and confirmed it by only disabling that Camera and then no crashes occur.

    As soon as we enable the Camera it continues playing for about 20 seconds and then the application crashes.
    Looking at the performance logs of the Quest 2, the FPS drops from 72FPS down to 42FPS.
    The CPU usually running at 60%-70% is not maxing out at 100% just before it crashes.

    The headset then throws a "Not enough memory to run application" error.

    I get the feeling that there's a memory leak on the Camera output to the render texture, but I have no idea how to address it.
    There is no code involved.
    It's just placing the camera in scene, and connecting the render texture as output.
    The Render Texture is then used on a URP/Unlit material.

    The Camera:
    I've also tried setting the culling mask to a layer only containing the 2 meshes that it would ever be able to see.
    1x 2D Unity Plane (512 texture)
    1x 80Poly Sphere (2048 texture)
    There is no Skybox, so I've also tried setting that to be a solid color.

    upload_2023-6-27_17-47-35.png

    The Render Texture:
    I've tried setting Depth Stencil Format to None as well.
    It didn't make a difference.
    Also tried dropping the resolution down to 128 x 128, also didn't make a difference.
    upload_2023-6-27_17-48-24.png

    The Material:
    upload_2023-6-27_17-51-43.png

    This was working fine in Unity 2021.3.x URP.
    We haven't made any changes to this scene.

    I will test in a empty blank Unity scene, and upload the results here as well.

    EDIT 1:
    Tested in a blank Unity Scene with only the XR Rig.
    The application still crashes after about 20 seconds, same settings as above.

    EDIT 2:
    Replicated the issue in a brand new Unity 2022.3.2f1 URP + Android application.
    Install Oculus Integration and applied recommended settings.
    Added a Camera and Render Texture to the scene, built, and got the exact same issue.
     
    Last edited: Jun 27, 2023
    Meatloaf4 and AlexBourgeois like this.
  2. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Meatloaf4 likes this.
  3. ManueleB

    ManueleB

    Unity Technologies

    Joined:
    Jul 6, 2020
    Posts:
    98
    Hey! We are aware of some memory leak issues caused by RTHandles in 22 LTS and we are working on a fix, if you can report a bug with a simple repro case then we can make sure that is the same issue and verify the fix

    Thanks!
     
  4. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Hey! Just released a bug report (IN-45663). It is very similar to the one I linked earlier, might be a duplicate.
    Very simple to reproduce in Unity 2022.3.3f1: in a fresh URP 3D project, create a second camera that outputs to a render texture, create a cube that uses the render texture as albedo, build this as a Developpment Build and monitor it with Unity Standalone Profiler to see the memory leak. Hope it helps !
     
    Meatloaf4 and ManueleB like this.
  5. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Quick update, my bug report got checked and reviewed. It is indeed a duplicate of the previous bug.
     
    Meatloaf4 likes this.
  6. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Hello! Is there any news or workaround for this bug?
    I see that the first bug report has also been identified as a duplicate of an older one. This “root” bug is dated from November 2022, so it has been almost 9 months since it was first reported. I understand that bugs can be hard to track down, but it is a major issue for my project and I need to know if it will still be there for another 6 months or not.
    If you have any tips, I take them,
    Thanks
     
  7. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    Hello also following up as I seem to be getting this issue now too after I updated to Unity 2022.3.1f1 (tested up to 3.4 and still the same issue).

    Is there a fix in the works, is there any workaround? This is a bit of a showstopper currently, and it would be great to get some insight from Unity.
     
    Sluggy likes this.
  8. PetraCephas

    PetraCephas

    Joined:
    Mar 27, 2014
    Posts:
    16
    Same issue here in 2022.3.4f1 and 2022.3.5f1 using URP.
     
    Meatloaf4 likes this.
  9. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    78
    Hey, I just want to give an update on the fix.

    We have prepared the code changes. I am addressing couple last issues and working on land the fix to trunk soon(also added test to prevent future regression like this). My estimate is the trunk change will land by EOW.
    I will backport the relevant fix to 22.3/staging once it lands.

    Thanks
     
  10. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    @ThomasZeng can not stress how much I appreciate this update.

    I understand that software dev is complex and bugs like this occur. That said, I also think it's extremely helpful and important to keep us devs in the loop, so we plan and work around these issues.

    Looking forward to the fix, and thanks for the hard work on getting this rolled out ASAP.
     
  11. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    840
    Yes, this is quite the relief knowing this is finally being addressed! Thank you for the update!
     
  12. JamesSozoLabs

    JamesSozoLabs

    Joined:
    Jan 10, 2022
    Posts:
    13
    @ThomasZeng Thank you so much for tackling this issue quickly.

    We were worried about the timeline for a fix, and started developing a work around.
    Glad to see that we don't need to spend more time on finding a solution though.
     
  13. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    @ThomasZeng just curious if you have an update on when the fix will be out.

    Thanks in advance!
     
  14. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    Sorry to be a pest but I'm really hoping for an ETA on the fix. This bug is a show stopper for us and I'm trying to decide if we should work on a more permanent workaround.

    Thanks in advance!
     
  15. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Meatloaf4 likes this.
  16. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    Want to once again follow up on this issue, in order to assess if it's gotten pushed to the wayside.

    As far as the bug ticket goes, it still says "Active", and not "In Progress". @ThomasZeng did say that the code changes were prepared, though, so I'm trying to assess if the ticket status is out of date or if there were issues with the fix.

    I (and I believe others) would really appreciate a status update on this, as this bug report looks to be one of the highest voted Active bug reports currently.

    If there is anything I can do to help move this issue forward, please let me know. At this juncture, I'm just looking for some clarity, though.

    Thank you in advance!
     
    AlexBourgeois likes this.
  17. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Hi, I will continue upping this thread. Does anybody has any news or found any workaround ? @ThomasZeng @ManueleB
    Deadlines are coming for me so I really need answers ...
    Also I don't understand how it is possible to not be able to use 2 cameras in Unity URP for so long, it has been there for almost 10 months ... Isn't it a big enough bug?
    Thanks,
     
  18. feylaputh

    feylaputh

    Joined:
    Aug 7, 2022
    Posts:
    2
    Hello there @ThomasZeng @ManueleB

    Any update? I have been waiting for a few months for the correction and I have my project to send ASAP.

    Thanks
    I look forward to your reply
    Jérémy
     
    Meatloaf4 and AlexBourgeois like this.
  19. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    I have this bug on the PC build. I have a minimap that is updated when a player does some actions. Some players report crashes. They get this in the logs:

    D3D11: Failed to create RenderTexture (2560 x 1600 fmt 27 aa 1), error 0x887a0005

    And then a crash.

    Any news on the fix?
     
    Meatloaf4 likes this.
  20. Boof

    Boof

    Joined:
    Aug 11, 2014
    Posts:
    10
    I am experiencing the bug on 2022.3.8f1, but not on 2022.3.4f1. I tried some workarounds but the issue seems to be embedded deep in the RenderTexture code. I think it's a problem specifically with RenderTextures and not with the Camera, but I haven't scoured the DirectX code (and I'm not very skilled) so maybe I'm wrong.

    If your project uses URP with RenderTextures then I don't see any reason to use future Unity versions until this bug has been resolved. I'm very surprised this made it past Unity's unit tests.
     
    Meatloaf4 likes this.
  21. AlexBourgeois

    AlexBourgeois

    Joined:
    Oct 30, 2017
    Posts:
    9
    Hi, it's time for a little "Up".

    @Boof I tried to replicate the bug with Unity 2022.3.4f1 and I can confirm that it does not occur! That is a great news! Thank you for sharing :)

    @ThomasZeng do you have any update on your side ?
    Thanks,
     
  22. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    Have you checked both DirectX 11 and DirectX 12? I've removed the second camera altogether. Now I draw pixels into runtime-generated textures directly from code for my minimap.
     
  23. FB-dtalker

    FB-dtalker

    Joined:
    Aug 10, 2018
    Posts:
    1
    Gratefully! It seems to have been fixed for version 2022.3.8f1!

    I had this problem with the 2022.3.5f1 version on my quest2, but found it fixed on the new version 2022.3.8f1.

    (I also tried to upgrade to the 2023.1.8f version but it still seems to be there.)
     
  24. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    78
    Hi all,
    Sorry for the late update :) .

    There are three issues in this space that I am aware of:
    The first issue fix (Editor performance drops) has landed to trunk and backported to 22.3 and 23.2.

    The second issue fix(RenderTexture leak issue) has landed to trunk and backported to 22.3(not released yet) and 23.2(not released yet). This fix will be included in the next 22.3 and 23.2 release. (discussed more in this forum thread)

    The third issue (RTHandle causes GC.Alloc) we believe it is a dup of the first issue. Our QA is validating that issue internally but we are likely gonna to close it as duplicate.

    Hope this helps,
    Thomas
     
  25. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    840
    Out of curiosity, has anyone had issues with camera stacking along with rendering to textures?

    I recently was working on adding a 3D skybox to my camera via a base camera and an overlay camera. Everything seemed to be working fine until I re-enabled the objects that were being rendered to a render texture. Then the overlay camera stopped working and I'm getting null-reference errors from within the URP pipeline itself. I don't have access to the project atm but I can post the error trace later.
     
  26. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    840
    So if I have a scene with three camera, one an overlay, one a base that will stack with the overlay, and another base that renders to a RenderTexture I get this null-reference error in the render pipeline.

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.CheckPostProcessForDepth () (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:979)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:746)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:362)
    UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
    UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

    The error ceases if I change the overlay camera to a base camera. However I do get the following error once. It doesn't appear to break anything and only happens once but still annoying nonetheless.


    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Rendering.VolumeManager.ReplaceData (UnityEngine.Rendering.VolumeStack stack) (at ./Library/PackageCache/com.unity.render-pipelines.core@14.0.7/Runtime/Volume/VolumeManager.cs:334)
    UnityEngine.Rendering.VolumeManager.Update (UnityEngine.Rendering.VolumeStack stack, UnityEngine.Transform trigger, UnityEngine.LayerMask layerMask) (at ./Library/PackageCache/com.unity.render-pipelines.core@14.0.7/Runtime/Volume/VolumeManager.cs:438)
    UnityEngine.Rendering.Universal.CameraExtensions.UpdateVolumeStack (UnityEngine.Camera camera, UnityEngine.Rendering.Universal.UniversalAdditionalCameraData cameraData) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalAdditionalCameraData.cs:217)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.UpdateVolumeFramework (UnityEngine.Camera camera, UnityEngine.Rendering.Universal.UniversalAdditionalCameraData additionalCameraData) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:941)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:784)
    UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:362)
    UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
    UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.A

    This was tried with Unity 2022.3.0f using the URP pipeline. Each camera had a different pipeline asset. Post processing was disabled on all pipeline assets.
     
  27. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    840
    Just to clarify, it appears that upgrading to 2022.3.9f fixed the issues. Thanks for that!
     
  28. Anibaaal

    Anibaaal

    Joined:
    Aug 15, 2021
    Posts:
    2
    Since updating my project to 2022.3.3f1 and then going through 4, 7, 8 and 9f1 (facing Canvas bugs too) I've been having memory leaks that happen when Depth and Opaque textures are enabled and the scene is rendering, doesn't matter if it's in Play mode or not. If I close the Scene and Game windows, the leak stops.
    I also tried starting a new project using URP template, copied my assets and the issue is still there.
    Can this be related?

    Edit: Some notes, the memory leak happens when Unity is in the background, looking at task manager makes it leak for example, if you are inside the Unity it doesn't leak. It also seems like this only happens when the platform is set to Android, I am now trying with WebGL and there are no leaks, also when I tested on a new project, there was no leak until I switched platform to Android.

     
    Last edited: Sep 12, 2023
    an_n, mortron and AlonMixed like this.
  29. TheBlueComet

    TheBlueComet

    Joined:
    Jul 9, 2021
    Posts:
    1
    Exactly the same problem here but with windows build. I'm using unity 2022.3.8f1.
     
    an_n likes this.
  30. AlonMixed

    AlonMixed

    Joined:
    Dec 10, 2017
    Posts:
    17
    After updating the project to 2022.3.9 from 2022.3.5 the project started to leak also. Closing and reopening both the scene and game views stopped the leak.
     
    Last edited: Sep 12, 2023
  31. MegaMileyStudios

    MegaMileyStudios

    Joined:
    Aug 19, 2017
    Posts:
    72
    Same here with 2022.3.9f1, currently downgrading to see if that resolves it. Let's hope the fixes Thomas is talking about will work for us.

    Just downgraded to 2022.3.7f1 and indeed there's no more massive memory leak (mine was able to fill up ~64Gb of RAM in about a minute). At least I can continue working now
     
  32. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    215
    If your particular leak disappears in 2022.3.7f1 but is present in 2022.3.8 and 2022.3.9 then it could be this: https://forum.unity.com/threads/rth...strophic-memory-leak-bug-in-2022-3-8.1486035/
     
  33. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    After updating to unity 2022.3.10f1 I still seem to be getting an issue that looks like it's tied to a camera render texture.

    If I remove the camera with the render texture the error goes away.

    The error I am now getting is

    [Assert] Assertion failed on expression: 'rs && rs->m_Texture && rs->m_SRView''.

    This is inside a play mode unit test. Anyone else experiencing an issue like this after the upgrade to 2022.3.10f1?

    My issue is only occuring when targeting Android.

    @Anibaaal it looks like we might be having the same issue. Did updating work for you by chance?
     
    Last edited: Oct 6, 2023
  34. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,156
    @Meatloaf4 While I don't have a complete picture of what bugs have been reported and fixe I do feel like most known leaks/issues in this rough area have been fixed so it would be super awesome if you could please file a bug report for what you're seeing here, so that too can get fixed :)
     
  35. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    182
    I would definitely file a bug report but currently it looks to only be occuring on a unity Cloud Build during unit testing.

    I think the likely cause is the low system specs on the build runners as I've tried to reproduce locally but I am unable to.

    Do you have any advice on how I might go about filing a bug report given the nature of how the bug manifests?

    With all this said, the bug does occur every time on build in cloud build so in theory is easily reproducible for my project.
     
  36. zhust2003

    zhust2003

    Joined:
    Jun 1, 2021
    Posts:
    2
    After upgrading Unity to version 2022.3.10f1, in our project, in any scene (including an empty one), if the application is left idle for a while, the memory usage will increase extremely rapidly and consume the entire machine's memory in 20 seconds.

    This issue only occurs on Android devices and has an extremely unpredictable frequency, being more likely to occur after a fresh installation of the application.

    However, if it connected Unity's Profiler during the idle period, this issue does not occur.

    This issue is extremely perplexing but has a significant impact. I've been attempting to resolve it for a month now, but have been unable to identify the root cause.

    I've noticed a certain correlation between this abnormal memory surge and RenderFeature. The probability of encountering this problem decreases when a few RenderFeatures are removed, and it appears to be closely tied to the Universal Render Pipeline (URP). We did not encounter this issue with the previous 2021 LTS version that we were using.
     

    Attached Files:

    Last edited: Oct 12, 2023
  37. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,156
    That Assert is D311 gfx backend related, are you using a different one on your machine?


    Hmm no idea but maybe with the log from cloud build?


    Hmm, perplexing indeed.
    1. Did you delete the library folder after upgrading?
    2. Do you get any logs in the Player logs or logcat when this happens?
    3. Which Unity version did you upgrade from?
    4. Which RenderFeatures does it seem to be connected to?
    5. Does this also happen in a non-development player?
     
  38. zhust2003

    zhust2003

    Joined:
    Jun 1, 2021
    Posts:
    2
    Q: Did you delete the library folder after upgrading?
    A: Yes, I've already try delete all library folder to rerun project and rebuild, it happened again.

    Q: Do you get any logs in the Player logs or logcat when this happens?
    A: I cannot found any valuable information from logcat, But I can upload a log for you.

    Q: Which Unity version did you upgrade from?
    A: I upgrade from unity 2021.3.9f1, ecs 0.51 and urp12, to 2022.3.3f1, urp 14.0.8 and ecs 1.0.16. I even try 2022.3.7f1, 2022.3.10f1, 2022.3.11f1, but all versions have that bug.

    Q: Which RenderFeatures does it seem to be connected to?
    A: Like Render Objects RenderFeature from urp, and some custom renderfeatures, like: outline, radial blur etc, But I found even I just only use Render Objects RenderFeature, that bug would happen.

    Q: Does this also happen in a non-development player?
    A: Yes, It even occurs in release package.

    After a few days, I found some new informations. because we use com.entities.graphics 1.0.16 library, Maybe it's bug from that? I'm not sure, but if I remove it totally, this problem disappear.
    And if I set total job queue equals 1, the probability of the bug occurring is pretty low.

    Because this bug appears randomly, I'm not particularly confident in the inference above. I have uploaded the adb logs from when the issue occurred, hoping it can be of help to you. Thank you for your assistance.
     

    Attached Files:

    Last edited: Oct 20, 2023
  39. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,156
    Thanks for the additional info @zhust2003
    This sounds like a separate and new issue (or maybe just a different expression of it but without a repro project it's impossible to tell) so we need to do a full analysis of it. Could you please file a bug report via the Editor menu
    Help > Report a Bug 
    ?