Search Unity

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:
    599
    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