Unity c#中嵌套循环中的StackOverflowException >> [

问题描述 投票:0回答:2
[在Unity c#中,我从json中获取数据,并且正在使用嵌套循环(如下代码)查找/比较游戏对象,以在本地游戏对象中设置该数据。但是在到达一定数量的对象(> 275)之后,我得到StackOverflowException错误。基本上80个时间循环运行10次,运行300次,请参见下面的代码。(注意:该代码可以以较低的数字运行,例如j <275时)。

public void SetDataInObject() { if (j < ObjList.objects.Count) //count is approx 300 { for (int k = 0; k < allObjs.Length; k++) // Length is 10 { stCalc = uiMana.floorStats[k].GetComponent<StatesCalc>(); for (int m = 0; m < allObjs[k].floorObjs.Length; m++) //Length is 80 { string serverObj = ObjList.objects[j].name; string localObj = allObjs[k].floorObjs[m].gameObject.name; if (localObj == serverObj) { ObjManager curObjManger = allObjs[k].floorObjs[m].GetComponent<ObjManager>(); //Logic to set data in local objects } } } j++; SetDataInObject(); } }

[在Unity c#中,我从json中获取数据,并且正在使用嵌套循环(如下代码)查找/比较游戏对象,以在本地游戏对象中设置该数据。但是在...
c# unity3d stack-overflow nested-loops
2个回答
2
投票
您正在SetDataInObject()内调用SetDataInObject而无法中断循环-因此您会得到堆栈溢出。 A调用A,然后调用A,又调用A,然后...

0
投票
您的问题在这条线上
© www.soinside.com 2019 - 2024. All rights reserved.