Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mono.CSharp.InternalErrorException when calling DOTween inside an IEnumerator

Discussion in 'Scripting' started by ironfiftynine, Sep 29, 2015.

  1. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    71
    Good day. I have the following function in my code.

    Code (CSharp):
    1. IEnumerator NextStep () {
    2.         Color newCol = Color.white;
    3.      
    4.         DOTween.To (()=> newCol, c => newCol = c, Color.black, 0.4f)
    5.             .OnUpdate (delegate () {
    6.                 cam.backgroundColor = newCol;
    7.                 logoCrystal.color = newCol;
    8.             });
    9.  
    10.         yield return new WaitForSeconds (0.3f);
    11.  
    12.         logo.transform.DOLocalMoveX (1f, 0.5f);
    13.  
    14.         yield return new WaitForSeconds (0.2f);
    15.  
    16.         logoPainting.DOColor (Color.white, 0.4f);
    17.  
    18.         yield return new WaitForSeconds (0.5f);
    19.  
    20.         tapText.DOColor (Color.white, 0.3f)
    21.             .OnComplete (delegate() {
    22.                 tapText.DOColor (new Color (1f, 1f, 0.8f), 0.15f).SetLoops(-1, LoopType.Yoyo);
    23.                 inputAllowed = true;
    24.             });
    25.     }
    It throws the following error upon compilation:

    Line 65 corresponds to the first DOTween call in my snippet. Further more, adding

    Code (CSharp):
    1. yield return new WaitForSeconds (0f);
    will resolve the error.

    I searched for any similar cases, but the closest I found would be the InternalErrorException caused by named parameters which is no the case in my code. Any ideas on this? Thank you very much,
     
  2. darbotron

    darbotron

    Joined:
    Aug 9, 2010
    Posts:
    351
    I've had a similar problem recently.

    From the error message and callstack reported on my machine it looks like there's a mono bug / limitation of the compiler where it can run out of space in internal buffers when processing anonymous lambdas inside IEnumerators.

    The workaround is to write a class that behaves the same way as the anonymous lambda that your code would cause the compiler to generate (if it wasn't broken!) and use that in place of the anonymous lambda.

    See this MSDN post for info on how anonymous lambdas are implemented: https://blogs.msdn.microsoft.com/oldnewthing/20060802-00/?p=30263

    Probably not what you wanted to hear, but there you are - hope this helps someone

    Alex
     
    ironfiftynine likes this.