XNA错误索引超出范围异常?

编程入门 行业动态 更新时间:2024-10-25 20:23:20
本文介绍了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错误索引超出范围异常?

本文发布于:2023-10-18 10:38:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   异常   错误   XNA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!