Tencent / InjectFix

InjectFix is a hot-fix solution library for Unity
Other
1.97k stars 418 forks source link

新增协程报错 #215

Open jinghuafumen opened 4 years ago

jinghuafumen commented 4 years ago

using System.Collections; using UnityEngine;

public class ZTest : MonoBehaviour { void Start() { Test(); }

[IFix.Patch]
void Test()
{
    StartCoroutine(TestCoroB());
}

IEnumerator TestCoroA()
{
    yield return null;
    Debug.Log("TestCoroA");
}

[IFix.Interpret]
IEnumerator TestCoroB()
{
    yield return new WaitForSeconds(1);
    Debug.Log("TestCoroB");
}

}

//如果代码里有TestCoroA,新增TestCoroB,没问题 //如果把TestCoroA删了,再新增TestCocoB,会报错 //报错提示: // KeyNotFoundException: The given key was not present in the dictionary. // System.Collections.Generic.Dictionary2[System.Reflection.MethodInfo,System.Int32].get_Item (System.Reflection.MethodInfo key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150) // IFix.Core.PatchManager.readSlotInfo (System.IO.BinaryReader reader, System.Collections.Generic.Dictionary2 itfMethodToId, System.Type[] externTypes, Int32 maxId) // IFix.Core.PatchManager.Load (System.IO.Stream stream)

annayxguo commented 4 years ago

如果之前有过返回 IEnumerator 类型的函数,那[IFix.Interpret]就没问题; 如果之前没有过,就得手动加个接口,把 IEnumerator 放到[IFix.CustomBridge]里。