Search Issue Tracker

Won't Fix

Votes

5

Found in

2017.3.0a1

2018.2.0a1

2018.2.12f1

2018.3.0a1

2019.1.0a1

Issue ID

1098168

Regression

No

Unity Editor crashes when using circular dependency due to stack overflow

Mono

-

Steps to reproduce:
1. Open attached project "case_1098168-Unity_Crash_1.zip"
2. Go to Window -> Asset Management -> Tech Tree Explorer
3. Press the "TechTree (TechThree.asset)" button
4. Pres "Tech Connections" button
5. Press "A" and then red "B" button

Actual result: Unity Editor crashes.

Reproduced in: 2017.4.17f1, 2018.2.20f1, 2018.3.0f2, 2019.1.0a12

Note: Editor crashes without a stack trace.

  1. Resolution Note:

    Spent a pretty substantial amount of time researching this issue as well as multiple attempts to fix it through various means. As was previously mentioned the main issue is that when a stack overflow is triggered by the OS (or by us) it will raise an exception which will trigger the finalizers to be called. This is a problem because occasionally the finalizers in Unity will call into MonoUtility's stack checking code and since we are already low on stack space it attempts to throw a stack overflow exception during a stack overflow exception. This leads to the editor terminating prematurely without any helpful information in the editor log.

    For history's sake here his an incomplete list of things I tried:
    - Dump a backtrace to the Editor log every time a stack overflow exception is thrown
    *** This generated a lot of noise in the log and also was not always a good indication of what exactly caused the editor to crash
    - Spin up a separate watchdog thread to allow us to unwind the thread that is having stack overflow issues
    *** In order for this to work we needed to let the watchdog thread know via native signal handling ie: sigsegv to attempt to unwind the thread and print the stack trace. This worked in certain scenarios but several of the known reproduction projects kill the editor before we are able to catch the signal in order to unwind the backtrace.
    - Set up some callbacks where mono would let unity when it was starting/finishing stack overflow exception handling to allow for us to prevent throwing a stack overflow exception on top of the one already being thrown
    *** Turns out even if we prevent throwing an additional stack overflow exception the finalizer loop still persists and we run out of stack space eventually that way.

Comments (4)

  1. PatriciaBarnes

    Oct 03, 2021 08:34

  2. Wappenull

    Sep 19, 2020 11:58

    I also got editor crash from c# stack overflow. Here is my case and how I got over it.

    https://forum.unity.com/threads/tips-troubleshooting-editor-crash-from-stackoverflowexception.973122/

  3. unity_3V1KwV8S0q8b-Q

    Jul 16, 2020 08:19

    Hi guys, for the best and free tech news today visit: https://vacoo.info/

  4. Frolll

    Jul 16, 2019 05:49

    This problem completely breaks the editor. The game mode starts for a very long time, the code compilation time increases.
    Unity 2018.4.4f1

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.