Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

IEnumerator Invoke causes app hard freeze only on apk execution

Discussion in 'Editor & General Support' started by tsibiski, May 16, 2018.

  1. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    124
    I have an IEnumerator that I use to invoke a specific method. This is part of a test framework. The purpose of this method is to launch a Test coroutine as if it was a helper method. The test runner logic knows to consider anything launched in this way as part of the test calling it - rather than its own test (because the method calling it is in fact its own test).

    While my workaround is to simply put all the test logic into a separate IEnumerator that is called in every place it is needed - and while under any other circumstance, that would clearly be the logical way to do it, and not a workaround - but under this very particular circumstance, I prefer the tests to be capable of being called as a helper method for some other test using the following logic.

    Code (CSharp):
    1.  
    2. public IEnumerator RunFloatingDependency(string dependencyName) {
    3.  
    4.      MethodInfo methodNonTest = FloatingDependencies.Find(x => x.Value.Name == dependencyName).Value;
    5.      Type typeNonTest = methodNonTest.ReflectedType;
    6.      MonoBehaviour monoNonTest = gameObject.AddComponent(typeNonTest) as MonoBehaviour;
    7.      _floatingDependenciesMonos.Add(monoNonTest);
    8.       yield return StartCoroutine((IEnumerator)methodNonTest.Invoke(monoNonTest, new object[]{ }));
    9.  
    10. }
    11.  
    This works exactly as intended when it is called in the Editor, from an ipa, from WebGL, and has worked fine in apk's in earlier versions of Unity (used it originally in 5.6.3). However, in my current version (2017.2.1p4), the entire apk hard freezes the moment invoke is called here. There are no errors logged. Logcat simply notes that the app has stopped responding. I cannot reproduce the issue with my platform set as android in the editor.
     
    Last edited: May 16, 2018