好的,首先我正在使用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错误索引超出范围异常?
发布评论