Hi,
I hope this is the right place to post this, otherwise please free free to move this thread or to let me know where I should have posted it.
The reason I am writing is because lately our project is crashing frequently when unloading a scene. The scene contains a lot of objects and lot of “singletons” using static references.
What is happening is that when SceneManager.LoadScene is invoked (LoadSceneAsync doesn’t change things) the editor and even a standalone windows build will crash. If visual studio debugger is attached when the crash happens both vs and unity (or the build) will freeze.
To diagnose the issue I tried WinDbg which apparently is capable of breaking before the crash occurs. The reported exception is a StackOveflowException with the stack trace shown in the attached picture.
What I can gather from it is that when unity unloads the scene it tries to collect unused objects from static refs and that operation somehow triggers an infinite recursion inside the mono garbage collector. I am not entirely sure this is true because I looked at the source code from the unity mono fork and I didn’t find any evidence of a possible infinite recursion (how that is even possible I have no idea).
Our editor version is 2018.2.20f1 and I believe this is a known unity bug solved in a later version (2080.3.x). In any case this only started to happen recently, although it’s unfortunately unclear when exactly we introduced this issue in the project. Apparently we did something that started triggering this issue with the gc.
I would appreciate immensely any help, and if somebody working at unity knows what the potential cause for this is, it would be great if he/she could let me know something. Unfortunately upgrading to latest unity editor is not an option for us right now, so I can’t go that way.
Thank you very much for any help!