XNA错误索引超出范围异常? [英] XNA false index out of bounds exception?

查看:106
本文介绍了XNA错误索引超出范围异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,首先我正在使用XNA 4,其次我正在使用ArrayLists.

现在的问题是,我不知道为什么会发生这些异常,但是它们确实会发生并且显然是错误的.

这是发生这种情况的代码:

Alright guys firstly I''m working with XNA 4, secondly I''m using ArrayLists.

Now the problem is, I have no idea why these exceptions occur however they DO occur and apparently incorrectly.

Here''s the code where it happens:

if (bullets.Count - 1 >= i)
                        {
                            bullets.RemoveAt(i);
                            bulDirVal.RemoveAt(i);
                        }




如您所见,我什至添加了if语句,因此除非"i"确实在ArrayList的范围内,否则它不会执行这些行.引发异常时,我的"i"值始终包含在范围内,而我不知道发生了什么.

我有什么要忽略的吗?




As you can see I even added the if statement so it wouldn''t execute those lines unless ''i'' is indeed within the range of the ArrayList. When the exception is thrown, my ''i'' value is always contained within the range, and I have no idea what is going on.

Is there anything I''m overlooking?

推荐答案

正如Edman所指出的,您只检查一个集合,还需要检查另一个集合.

另一种可能性是您有多个线程可能正在访问同一集合.如果是这样,则需要在其中添加一些线程同步.
As Edman pointed out, you only check one collection, you also need to check the other one.

Another possibility is that you have multiple threads that may be accessing the same collection. If so, you need to add some thread-sync in there.


这篇关于XNA错误索引超出范围异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆