Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Possible Unity Mono compiler bug.

Discussion in 'Editor & General Support' started by Eugenio, Sep 18, 2014.

  1. Eugenio

    Eugenio

    Joined:
    Mar 21, 2013
    Posts:
    197
    Hello everyone.
    Today I got a
    Code (CSharp):
    1. Internal compiler error.
    that took me 20 minutes to figure out what it was.
    Basically in a coroutine I was calling a
    Code (CSharp):
    1. yield break;
    inside of a lambda expression that was a callback of another coroutine. Just putting the yield inside of the callback will create the compiler error.
    Apparently it is not possible to do that but the compiler will crash instead of returning and error.
    Attached to this message you'll find a script I made to reproduce the error.
    Here is the code anyway:
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class UnityCompilerCrasher : MonoBehaviour {
    5.  
    6.     public delegate void MyCallback (string result);
    7.  
    8.     protected void Start () {
    9.         StartCoroutine (MyCoroutine (1, (string result) => {
    10.             Debug.Log (result);
    11.         }));
    12.     }
    13.  
    14.     private IEnumerator MyCoroutine (int parameter, MyCallback callback) {
    15.         parameter += 100;
    16.         yield return new WaitForSeconds (1f);
    17.         StartCoroutine (AnotherCoroutine (parameter, (string result) => {
    18.             if (result.Equals ("dummy")) {
    19.                 // COMMENT THE NEXT LINE TO AVOID THE INTERNAL ERROR !!!
    20.                 yield break;
    21.             }
    22.             if (callback != null) {
    23.                 callback (result);
    24.             }
    25.         }));
    26.     }
    27.  
    28.     private IEnumerator AnotherCoroutine (int parameter, MyCallback callback) {
    29.         yield return new WaitForEndOfFrame ();
    30.         if (callback != null) {
    31.             callback ("" + parameter);
    32.         }
    33.     }
    34. }
    Almost forgot: using Unity 4.5.3f3.

    Cheers :)
     

    Attached Files:

  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Probably worth sending that as a bug report, so the QA team can dive into it.
     
  3. Eugenio

    Eugenio

    Joined:
    Mar 21, 2013
    Posts:
    197
    Thanks Graham, I'll do tomorrow !!! :)