Search Issue Tracker
CPU usage spikes in the Loading.LockPersistentManager when async loading/unloading Scenes
How to reproduce:
1. Open the attached "ReproProject.zip" project
2. Open the "Game Streamer Scene" Scene (Assets/NatureManufacture Assets/WorldStreamer/Tutorial Work and Game Scenes)
3. Make sure the Profiler window is opened (Window -> Analysis -> Profiler)
4. Enter Play Mode
5. Move the Camera in the Game view with WASD keys while holding the shift key on the keyboard
6. Press the Pause button when huge CPU usage spikes in the Profiler window are visible
7. Observe the Profiler's Overview section of the spikes
Expected result: No CPU usage spikes are in the Loading.LockPersistentManager in the Profiler's Overview section
Actual result: A huge CPU usage spike in the Loading.LockPersistentManager (Around 60 % usage can be seen in the Profiler's Overview section)
Reproducible with: 2019.4.13f1, 2020.1.10f1, 2020.2.0b8, 2021.1.0a1
Could not test with: 2018.4.28f1 (Due to errors with missing functionality)
- Originally the case was reported against terrain as the spike happens inside CullAllTerrains.
- After investigation we found the true reason behind it was that the PersistentManager locks up all PPtr dereferences while scenes are being asynchronously loaded.
- The original case was then resolved as fixed (1276854) but the fix was only for terrain, where it tries to avoid PPtr dereferencing as much as possible.
- But the real fix is still yet to be made because PPtr can still happen anywhere, including in user scripts. Steen said it won't be an easy fix for PersistentManager not to lock up the main thread.
- Keep this bug here so we can track the progress.
Feb 18, 2022 03:12
This bug makes testing game in editor unplayable cause every time I load new scene with LoadSceneAsync() in got stuck in LOCKPERSISTENTMANAGER per 1 minute.
Apr 07, 2021 16:30
Same here Unity 2020.2.0f
Mar 27, 2021 08:35
My comment above is utilizing latest 2019 LTS
Mar 27, 2021 08:33
I encounter this issue, or an issue related to this where my scene is stuck loading - very difficult to reproduce, as it doesn't happen often.
As of writing this, my editor is currently stuck waiting for the past 20 minutes, and the following is the callstack obtained.
Best guess is a mutex is stuck waiting to be locked, based on the .dmp and callstack obtained:
> Unity.exe!PersistentManager::Lock(enum PersistentManager::LockFlags,class profiling::Marker *) Unknown
Unity.exe!PersistentManager::ReadObject(int,enum AwakeFromLoadMode) Unknown
Unity.exe!PPtr<class Object>::operator class Object *(void) Unknown
mono-2.0-bdwgc.dll!mono_jit_runtime_invoke(_MonoMethod * method, void * obj, void * * params, _MonoObject * * exc, _MonoError * error) Line 2809 C
mono-2.0-bdwgc.dll!do_runtime_invoke(_MonoMethod * method, void * obj, void * * params, _MonoObject * * exc, _MonoError * error) Line 2921 C
mono-2.0-bdwgc.dll!mono_runtime_invoke_checked(_MonoMethod * method, void * obj, void * * params, _MonoError * error) Line 3073 C
mono-2.0-bdwgc.dll!mono_runtime_try_invoke_array(_MonoMethod * method, void * obj, _MonoArray * params, _MonoObject * * exc, _MonoError * error) Line 5264 C
mono-2.0-bdwgc.dll!mono_runtime_invoke_array_checked(_MonoMethod * method, void * obj, _MonoArray * params, _MonoError * error) Line 5142 C
mono-2.0-bdwgc.dll!ves_icall_InternalInvoke(_MonoReflectionMethod * method, _MonoObject * this_arg, _MonoArray * params, _MonoException * * exc) Line 3358 C
mono-2.0-bdwgc.dll!mono_method_signature(_MonoMethod * m) Line 2611 C
Fortunately isn't a 100% occurrence, but when it does occur it's always frustrating, and a bit of a blocker due to the randomness of how it occurs when it occurs.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- "ArgumentNullException" error in the Console when selecting certain ScriptableObjects and entering Play Mode
- Configurable joints become bouncier when setting "Bounciness" below 1
- Prefabs get corrupted when editing Particle System curves
- Colors on images become darker when enabling "Vertex Color Always in Gamma Color Space"
- Pausing a Visual Effect doesn't pause the “Multiply size over life” effect in the Update Block
The original issue was fixed and the generic case is unlikely to get fixed. They need to be treated case by case by the system owners.