[Unity]WaitForSeconds(float.NaN)的异常表现
2019/11
01
16:11
记Unity2018.4协程Coroutine的WaitForSeconds(float.Nan)的异常表现
一、异常协程体:
public class ExceptionCorout : MonoBehaviour
{
IEnumerator WaitTask()
{
var c = 1.0f;
var d = c - c;
var f = 0 / d;
yield return new WaitForSeconds(f);
}
void Start()
{
StartCoroutine(WaitTask());
}
public static void Execute()
{
GameObject go = new GameObject("go");
go.AddComponent<ExceptionCorout>();
}
}
以下代码执行必报错
float.NaN has been passed into WaitForSeconds which will result in an infinite wait time.
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
<Fire>c__Iterator1:MoveNext() (at Assets/ExceptionCorout.cs:20)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
然后后续创建的脚本,均不再执行Start()函数体
五、结论
WaitForSeconds,传入无效Nan参数,会堵住整个协程系统
CopyRights: The Post by BY-NC-SA For Authorization,Original If Not Noted,Reprint Please Indicate From 老刘@开发笔记
Post Link: [Unity]WaitForSeconds(float.NaN)的异常表现
Post Link: [Unity]WaitForSeconds(float.NaN)的异常表现