加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[Unity3D]InvalidOperationException: out of sync

(2013-01-22 20:09:29)
标签:

bug

invalidoperationexce

sync

it

分类: Unity3d
详细信息:
InvalidOperationException: 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);
}

http://s8/mw690/5b6cb950gd931be5dfb87&690out of sync" TITLE="[Unity3D]InvalidOperationException: out of sync" />


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有