Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DayyanSisson · Jan 25, 2013 at 03:40 AM · listargumentexception

ArgumentOutOfRangeException When Argument Is Not Out Of Range

So I'm getting an ArgumentOutOfRangeException error that makes no sense to me. Whenever it tries to access a certain variable at a particular index in a List<>, I run a check to see if the List<> count is actually greater than or equal to the index I'm trying to access, but yet I still get the error. So I debugged it to see if maybe it was still searching for an out of range index, but it was searching for objects well within the List. Sometimes it would look for the 13th index in a List with 27 items, which means that an object should be there, yet I still get the error. I've checked all the times the error comes out, and every time is still gives me the error. So my question is whether or not ArgumentOutOfRangeException only refers to checking for an index outside of the range of the List, or to other things too?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jake.OConnor · Jan 25, 2013 at 03:45 AM 0
Share

ArgumentOutOfRangeExceptions are only thrown when array bounds are exceeded. There's probably a typo or logic error. Also, list.count has to be GREATER than the index (not greater-than-or-equal-to) because array indices are 0-based. Post some code?

avatar image DayyanSisson · Jan 25, 2013 at 04:34 AM 0
Share

Sorry, I didn't mean greater than or equal to. In any case, the count is greater than the index. Here's the code to find the index:

 int column = 0;
 int row = 0;
 int a = 0;
 while(a < nodes.Count){
     int b = 0;
     while(b < nodes[a].nodeCount){
         if(nodes[a].nodes[b].node == current.node){
             column = a;
             row = b;
         }
         b++;
     }
     a++;
 }

And here's the code where the error pops up:

     if(row < (nodes[column].nodeCount-1)){
         Node down = nodes[column].nodes[row+1];
         //Some code in here
         if(column < numberOfColumns){
             Node downRight = nodes[column+1].nodes[row+1];
             //Some code in here
         }
      }

So the first if-statement is checks to see if the row it wants to check actually exists (checks to see how many nodes is in the current column). Then it tries to assign the variable but then says the argument is out of range, although it can't be due to the check, and even if it could, the index it's checking is within the range of the list.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Loius · Jan 25, 2013 at 04:55 AM

nodeCount is a custom variable, which could be wrong.

Arrays are zero-based, so array[length-1+1] = array[length] is always null. Your +1 additions are pushing row and column out of bounds.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DayyanSisson · Jan 26, 2013 at 01:12 AM 0
Share

Checked the nodeCount variable, and it's all within that. And the checks make sure that it will never look for a node out of bounds. In any case, the error is popping up in the middle of the array, in which there is no risk of it being less than 0 or greater than the length of the array.

avatar image Wolfram · Jan 26, 2013 at 01:18 AM 0
Share

In the middle of both the column and row array?

Assu$$anonymous$$g that numberOfColumns==nodes.Count (if not, what's the difference?), you will run into an exception if you are in the last column, where column==numberOfColumns-1, because then you are accessing nodes[column+1], which is outside the array.

avatar image DayyanSisson · Jan 26, 2013 at 01:54 AM 0
Share

Yes in the middle of both arrays. And the difference is the number of columns is constant (in my case, 27) and nodes.Count is the number of nodes in the column (the # of rows).

avatar image Wolfram · Jan 26, 2013 at 02:00 AM 0
Share

That can't be right, as according to your code your first index (and therefore nodes.Count is #columns) selects the columns, and your second index (nodes[column].nodes.Count is #rows) is for the rows. How many rows do you have?

avatar image DayyanSisson · Jan 26, 2013 at 02:02 AM 0
Share

That depends. It changes per column.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

A respawn script for enemies. 1 Answer

How to Repair Argument is Out of Range 1 Answer

List Works But Still Get Argument Out of Range Exception 1 Answer

Why does List .ToArray throw ArgumentException? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges