- Home /
array problem
i get this error
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
8
System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections/ArrayList.cs:3261)
System.Collections.ArrayList.get_Item (Int32 index) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections/ArrayList.cs:2652)
UnityScript.Lang.Array.get_Item (Int32 index)
LODSystemEditor.CollapseTest () (at Assets/LODSystem/Editor/LODSystemEditor.js:314)
LODSystemEditor.ComputeProgressiveMesh () (at Assets/LODSystem/Editor/LODSystemEditor.js:699)
LODSystemEditor.PreCalculate (UnityEngine.Mesh tmpMesh) (at Assets/LODSystem/Editor/LODSystemEditor.js:464)
LODEditor.OnInspectorGUI () (at Assets/LODSystem/Editor/LODEditor.js:307)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty)
UnityEditor.DockArea:OnGUI()
with this piece of code
for (i = u.face.length - 1; i >= 0; --i) {
uFace = u.face[i];
if (uFace.HasVertex(v)) {
uFace.deTriangle( his ); // é£æ¥ãããªãã¡ã¬ã³ã¹ãé¤å¤
}
}
this script is a lod system from http://www.macroseed.com/Projects/Unity/Level_of_Detail_System
please help i need this script to work
Thanks Dj
UPDATE : i put a debug.log to display u.face.length and it displayed i and u.face.length as 5
I would guess that uFace.deTriangle is modifying the number of faces in u.face. Add a Debug.Log message before the uface - u.face[i] line and display the value of i and u.face.length.
Well one problem I can see (maybe) is you are pre subtracting the i.
the way i would do this is:
for (i = u.face.length - 1; i >= 0; i--) {
uFace = u.face[i];
if (uFace.HasVertex(v)) {
uFace.deTriangle( his );
}
}
or if you want to use --i then switch
i>=0 and i= u.face.length -1
to i > 0
and i = u.face.length
which means even if you pre subtract you will never go past 0. Also like the comment to your question(I think that is the logic of it)
right before the for loop add a debug statement that outputs length then right before u.face[i] put a debug statement what i is.
The iterator (i-- in this case) doesn't execute until after the loop body executes, so it doesn't matter if you pre- or post-increment.
I have used you code and ran a test and theoretically it should work. What kind of what kind of variable is uFace and how does it work, maybe it is the hasVertex function that is crashing it.
Answer by moinchdog · Dec 22, 2012 at 12:38 AM
i got it working by doing this
for (i = u.face.length; i > 0; i--) {
i=i-1;
uFace = u.face[i];
if (uFace.HasVertex(v)) {
uFace.deTriangle( his ); // é£æ¥ãããªãã¡ã¬ã³ã¹ãé¤å¤
}
}
and it works
thanks for your help guys.
Your answer
Follow this Question
Related Questions
IndexOutOfRangeExeption - Array index is out of range 2 Answers
IndexOutOfRangeException: Array index is out of range 2 Answers
Adding a texture to array textures?! 1 Answer
C# array not behaving as expected 0 Answers
NullReferenceException array 2 Answers