Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Application.Shutdown.CleanupMono never finishes.

Discussion in 'Editor & General Support' started by WinterboltGames, May 30, 2021.

  1. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Also happening in 2022.3.4
     
  2. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    And 2022.3.5f1.

    I never saw this in 2021x or prior.

    And with the constant shutting down via task manager I now get corrupted libraries and have to rebuild those more often.
     
  3. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
    I'm not even sure how to debug this. The editor log doesn't say anything useful, and the profiler stops responding when the popup appears.

    I haven't been able to reproduce it consistently either. Sometimes it shuts down without issue, other times it hangs- usually after doing a good amount of work in the editor.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    Can you capture a dump file of Unity.exe from the task manager when this happens and send it to me?
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    Thanks for the dump. Can you try removing com.unity.localization package from your project and check if that makes this go away?

    Also, can you tell me how long you waited before you captured the dump? Was it at least 30 seconds?
     
  6. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
    Yes, I have waited at least 30 seconds. One time I let it run and it did finish after 12 minutes(I checked the editor log).

    I will look into removing the localization package, but it will not be trivial because it is used throughout the code. I do have another issue with the localization package which may be related and which I have reported.- https://forum.unity.com/threads/obj...-during-a-domain-backup.1461953/#post-9153218
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    The dump is pointing at execution being stuck in the finalizer of UnityEditor.Localization.UI.LocalizedReferencePropertyDrawer`1 class. It is unsubscribing from a global static event, which at the time of the dump capture has 26651 subscriptions. Unsubscribing from an event that has a lot of subscriptions is a pretty heavy operation:

    1. Find the delegate in the delegate array you need to remove;
    2. Allocate a new array of "size - 1";
    2. Copy all the elements except the one you're trying to remove to the new array.

    This is easily O(n) operation where n is the number of event subscriptions. Now you take 26k of them and that explains why it takes so long to clean up. I'll bring this up internally.
     
    jRocket likes this.
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,158
    Hi,

    I have done some investigation into the localization issue. It would appear to be an issue with property drawers. The finalizer doesnt seem to get called until entering playmode or an assembly reload is going to occur. This can cause a lot of property drawers to leak over time which all then clean themselves up later on.
    I have created a bug so you can track the issue https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-44220
     
    Nefahl and jRocket like this.
  9. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,158
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
  12. The-White-Guardian

    The-White-Guardian

    Joined:
    May 16, 2019
    Posts:
    4
    Wanted to stick my oar in as well, because I was having this issue, too. Unity 2022.3.2f1, DOTS packages installed (Entities, Entities Graphics, Unity Physics, Burst, Mathematics & Packages). Shutting down Unity would put me in an endless loop of 'CleanupMono'.

    In my case the culprit was... Shader Graph! Closing the two Graph Editors I still had open completely fixed it. As was reported previously, try closing unnecessary EditorWindow instances. One of them is possibly bugged and stalling.
     
    jRocket likes this.
  13. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
    I looked into this further in my project and thought I would share my findings. While the root cause is still "property drawers not being finalized", what was causing thousands and thousands of event subscription in the LocalizedString property drawer in the first place was in fact the Odin Inspector package on the asset store. For whatever reason, the Localization module in Odin causes LocalizedString property drawers to be constructed every gui event update, so even doing a mousemove over the property drawer would cause it to be constructed every frame. I have tested normal property drawers and they are just constructed once.
     
    karl_jones likes this.
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,158
    That's strange. There's supposed to be an exception in Odin to prevent it from drawing the localization property drawers because it tends to break them. You can tell when it's drawing them because the table selection popup gets replaced by 2 text fields. Maybe this is a bug in Odin when dealing with ignored fields.
     
  15. IGIKorea

    IGIKorea

    Joined:
    Feb 23, 2021
    Posts:
    1
    I build my project once and resolve this problem
     
  16. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    186
    This issue does seem strange - we will look into it and get it resolved promptly if our Localization module is at fault :) It's possible there's some problem in how we manage the lifetime of the Unity property drawers we create in certain situations.
     
    Nefahl and karl_jones like this.
  17. jeffdyerSRTMarine

    jeffdyerSRTMarine

    Joined:
    Jan 23, 2019
    Posts:
    12
    I get this a lot with text mesh pro, we have an application with potentially thousands of labels (for moving ship names) and often it hangs in the unsubscribing of all the labels - this can be seen by pausing VS and viewing the threads, there's usually one running after the application has stopped and just hangs the Editor UI
     
  18. LastFractal

    LastFractal

    Joined:
    Mar 6, 2022
    Posts:
    28
    Still present in 2022.3.10f1.

    upload_2023-10-9_21-9-46.png
     
  19. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,158
    I've been working on a modification that introduces support for IDisposable to property drawers, although it hasn't been merged yet. To utilize this enhancement, you'll require both the Unity version incorporating this support and the updated localization package, likely to be included in version 1.5.0 (currently not available).

    Regarding the recent issue, I haven't identified a specific reason for it emerging after a particular Unity version. There don't seem to be any unusual elements in the property drawer code that could have exacerbated the situation. I suspect there may be more than one root cause for this issue.

    If you're not utilizing the localization package, the issue you're facing is likely unrelated, and the mentioned solutions won't apply. If you have encountered this in an example project, I encourage you to file a bug report for further investigation.
     
    Last edited: Oct 9, 2023
    mushragames, jRocket and LastFractal like this.
  20. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,396
    Completely off-topic, but while you're there could you introduce a virtual
    Initialize()
    method to property drawers at the same time? Combined with IDispoable support, it would make them about 200% more useful.
     
  21. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,158
    I'm afraid it's too late now, my pr is just going through review. What would initialize do that you can't do in the constructor or the Attach to panel event when using UI Toolkit?
     
  22. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,396
    Well I didn't know you could use a constructor as nothing in the docs indicates that you can do that. Having a method one can override would be immediately obvious as to its purpose even without documentation.

    Understand it's not an issue with UI toolkit as it doesn't run every repaint, though there's still lots of situations where we need to use IMGUI as we can't use UI Toolkit inside of IMGUI editor.

    Pretty much every kind of Odin Inspector drawer and processor has a virtual
    Initialize()
    method. A constructor could be used, sure, but it's just an immediately obvious thing to have that makes using their API so much better.
     
  23. SteenPetersen

    SteenPetersen

    Joined:
    Mar 13, 2016
    Posts:
    102
    Just a heads up that this fixed the issue for em as as well, closing the Shader graph tab. unity 2022.3 LTS
     
  24. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    186
    To add to this, I want to note that we finally did track down the cause of this issue (which in the case of Localization + Odin, was on our end - it seems other assets/packages are causing similar trouble as well). With the release of Odin 3.2 the issue should be resolved.

    The way Localization drawers are called is also totally different now, and Odin should not be causing any trouble drawing Localization types at all any more. We are also working on a far improved custom support module for Localization that includes lots of extra Odin niceness and extra functionality that should hopefully greatly improve the experience of using Unity's Localization package :)
     
  25. ArtemPavlovskyi

    ArtemPavlovskyi

    Joined:
    Apr 10, 2021
    Posts:
    4
    Omg, That helped like a charm!
     
  26. zt0725

    zt0725

    Joined:
    Apr 20, 2022
    Posts:
    2
  27. zt0725

    zt0725

    Joined:
    Apr 20, 2022
    Posts:
    2
    2022.3.16f1
     
  28. Banksy0987

    Banksy0987

    Joined:
    Nov 17, 2023
    Posts:
    2
    2022.3.16f1 LTS
    upload_2024-1-10_1-15-20.png
     
  29. Banksy0987

    Banksy0987

    Joined:
    Nov 17, 2023
    Posts:
    2
    this bug is rise up every time. stress...
     
  30. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    131
    It hapens to me since I started using Odin as well, but at the same time I switched to new Localization package and newer version of Unity, so not sure what causing it yet.
    Currently it happened with Unity 2023.2.7f1, Odin 3.2.1.0 and Localization 1.4.5 o_O
     
  31. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    117
    This problem persists in version v.2022.3.19f1

    In my case, it has something to do with the number of gameobjects in the scene.

    If my scene has few gameobjects then the application quits properly, but if the scene has many objects then it freezes when I call Application.Quit

    This is what I get on Player.log :

    ---
    [ALLOC_TEMP_TLS] TLS Allocator
    StackAllocators :
    [ALLOC_TEMP_MAIN]
    Peak usage frame count: [256.0 KB-0.5 MB]: 256 frames, [0.5 MB-1.0 MB]: 439 frames, [1.0 MB-2.0 MB]: 1 frames, [4.0 MB-8.0 MB]: 3 frames
    Initial Block Size 4.0 MB
    Current Block Size 6.5 MB
    Peak Allocated Bytes 6.5 MB
    Overflow Count 0
    [ALLOC_TEMP_Background Job.worker 4]
    Initial Block Size 32.0 KB
    Current Block Size 32.0 KB
    Peak Allocated Bytes 54 B
    Overflow Count 0
    [ALLOC_TEMP_Loading.PreloadManager]
    Initial Block Size 256.0 KB
    Current Block Size 504.0 KB
    Peak Allocated Bytes 486.6 KB
    Overflow Count 53
    .....
    [Many blocks like this]

    Any ideas on this?
     
    Last edited: Feb 28, 2024 at 4:17 PM
    amateurd likes this.
  32. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    183
    Problem still exists!