algorithmic modeling for Rhino
Below is a code snippet of my ShowForm() method, which is used with my winforms.
The error I am receiving is:
Some diagnostic information:
1. I know that the if-statement is hit, because of a MessageBox.Show() method I put there. I am thinking the for-loop is somehow indexing out, but I'm not quite sure why it is doing so.
2. The x.Count: is 7
3. Doing MessageBox.Show(Params.Index[0].ToString()); to check if Params.Index[0] is empty crashes my program every time without fail. What could that mean?
Tags:
Hi,
Well the reason it's crashing is because you're trying to access an array in an invalid index.
You're accessing only two arrays Params.Input & x.
The access to x seems alright, tho you need to notice that you're accessing from index 0 to count - 1. which means if you have only 1 element in the array you're not accessing anything. you should lose the '-1' because you're already limiting the loop to a number that is < than count. (using -1 would be logical if you're limiting it by <=)
You need to check for Params.Input length before accessing it, my guess is that it's empty and therefor accessing it in the 0 index raises an exception. and that is your bug
for your 3rd question -if you have an exception that is not handled Rhino will exit at once. Accessing Param.Input[0] WILL raise an exception if Param.Input is empty or null.
I suggest that next time before accessing any arrays make sure they're not null/empty and that your index is valid for that array.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by