C
C#2y ago
Zfx

❔ Out of bound error

I get this error : ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <f3aec01a34d14c7080754e28743c8472>:0) Tore.GénérerBordures () (at Assets/Scripts/Tore.cs:82) Tore.Awake () (at Assets/Scripts/Tore.cs:40) and I don't really understand why it does that ngl. Here's the code for the 'tore' class (which basically creates a torus)
27 Replies
Zfx
ZfxOP2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Zfx
ZfxOP2y ago
BlazeBin - ecbfhdwygysm
A tool for sharing your source code with the world!
Angius
Angius2y ago
Well, the error is quite clear You have some collection of, say, 3 items, but you're trying to access the 4th one
Zfx
ZfxOP2y ago
Yeah ik, the index goes out of bound, but I don't get how that's possible
phaseshift
phaseshift2y ago
You should $debug then
MODiX
MODiX2y ago
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Zfx
ZfxOP2y ago
I doubt I can use the debugger when it's attached to unity or maybe I can but don't know how to do it, since it's not the same I tried Yeah, but I see the error is in "générerBordures" but if you look at the error, it says the error is from tore.cs:82 right Oh wait
Zfx
ZfxOP2y ago
Actually, the errors comes from line 82 right
Zfx
ZfxOP2y ago
but then, if you look at this (that creates pointstore)
Zfx
ZfxOP2y ago
I don't get how it goes out of index. I understand it does, but idk how
Angius
Angius2y ago
My bet is on y + 1 being one too much
Zfx
ZfxOP2y ago
ooh Alright, so I have to find a way to get the left hand side differently than doing [y+1] - [y] which i don't even know why I,m doing
Angius
Angius2y ago
I mean, just a hunch I might not be correct But another way would be doing
for (var i = 1; i < list.Count; i++)
{
list[i - 1] - list[i];
}
for (var i = 1; i < list.Count; i++)
{
list[i - 1] - list[i];
}
Servator
Servator2y ago
I didn't check the code but are you sure its y <= x ?
Angius
Angius2y ago
Was about to say Should probably be < not <=
Zfx
ZfxOP2y ago
Isn't that the same thing?
Angius
Angius2y ago
Yeah
Zfx
ZfxOP2y ago
oh wait no I didn't do y < x which is basically list.count -1 I did y <= x you think that would fix it ? I'll try
MODiX
MODiX2y ago
Samarichitane#3472
REPL Result: Success
for(var i = 0; i < 5; i++) { Console.WriteLine(i); }
for(var i = 0; i < 5; i++) { Console.WriteLine(i); }
Console Output
0
1
2
3
4
0
1
2
3
4
Compile: 585.474ms | Execution: 42.586ms | React with ❌ to remove this embed.
Servator
Servator2y ago
Did it output 5? I mean You really need to write list.count-1 ?
Zfx
ZfxOP2y ago
Bro I've been trying to fix this for the past 8 hours You guys fkg saved my life send me your paypal or smth 😂 🙏
Servator
Servator2y ago
Not needed also forbidden
Zfx
ZfxOP2y ago
ye ik Hence why I put a laughing emoji but god fkg damn it Thank you guys
Servator
Servator2y ago
np You can close the thread with /close
Zfx
ZfxOP2y ago
Thank you so much Will do
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server