[Unity3D]InvalidOperationException: out of sync

详细信息:
InvalidOperationExceptio n: out of sync
System.Collections.Generic.Dictionary`2+Enumerator[UnityEngine.KeyCode,System.Boolean].VerifyState ()
System.Collections.Generic.Dictionary`2+Enumerator[UnityEngine.KeyCode,System.Boolean].MoveNext ()
System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[UnityEngine.KeyCode,System.Boolean].MoveNext ()
InputManager.CheckControleKyes () 
MMOController.FixedUpdate () 


从信息上看来,是用了DICTIONNARY的问题。经过查阅资料,发现问题出在迭代修改DICTIONARY的地方:

foreach (string key in dict.Keys)
{
        temp = dictAssetBundleRefs.TryGetValue(key, out value);
        修改temp的值
        或者删除temp
}

不可以迭代去修改dictionnary,正如我看到一个帖子写的:

You are modifying the dictionary while iterating over it. This is a big no-no.

批量修改或删除应当先将其作为BUFFER引出来再改,然后在一个个删除。

var buffer = new List<KeyKode>(Controlekeys.Keys); 
foreach(var key in buffer)
{
//修改你想要修改的东西
}


===================我直接获取引用来删除:如下记录=========================
AssetBundleRef[] abRefs = new AssetBundleRef[dictAssetBundleRefs.Count];
int i = 0;
foreach (string key in dictAssetBundleRefs.Keys)
{
         dictAssetBundleRefs.TryGetValue(key, out abRefs[i]);
         i++;  
}
i--;
for (int j = 0; j < abRefs.Length; j++)
{
         abRefs[j].assetBundle.Unload(false);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值