- Home /
IL2CPP problem on AddRange(List<>)?
Hello there,
So I've been building the game with Mono 2.x for a while now and there seems to be no problem with Mono. However when I build with IL2CPP, in some part of the game, AddRange doesn't run correctly.
Is there a known issue or are there any workarounds?
I believe that AddRange is working correctly in most cases. Can you provide a few more details? For example what is the type of the generic parameter use with List? What happens when AddRange does not work correctly. Does it throw an exception? Thanks.
if (Accessor.GameStateScript.CurGameState == GameStateEnum.Tutorial)
{
List<Gesture> tempGestureList = new List<Gesture>();
tempGestureList.AddRange(_tutorialGestures);
tempGestureList.AddRange(_cur$$anonymous$$apGestures);
result = GestureRecognizer.ProtractorRecognize(vector, onScreenGesture.points[0], onScreenGesture.points[1], tempGestureList);
}
////////
public class Gesture
{
public List<Unistroke> unistrokes;
public List<Vector2> points;
public GestureTypeEnum type;
public Vector2 lastTouchPoint;
public Gesture()
{
unistrokes = new List<Unistroke>();
points = new List<Vector2>();
lastTouchPoint = new Vector2();
}
public Gesture(List<Vector2> pointList)
{
unistrokes = new List<Unistroke>();
points = new List<Vector2>();
//points.AddRange(pointList);
points.InsertRange(0, pointList);
lastTouchPoint = new Vector2();
unistrokes.Add(new Unistroke(points));
List<Vector2> reversedPoints = new List<Vector2>();
for (int i = points.Count - 1; i >= 0; i--)
{
reversedPoints.Add(points[i]);
}
unistrokes.Add(new Unistroke(reversedPoints));
}
public Gesture(List<Vector2> pointList, Unistroke u1, Unistroke u2)
{
points = new List<Vector2>();
//points.AddRange(pointList);
points.InsertRange(0, pointList);
lastTouchPoint = new Vector2();
this.unistrokes = new List<Unistroke>();
unistrokes.Add(u1);
unistrokes.Add(u2);
}
~Gesture()
{
}
}
It works totally fine in $$anonymous$$ono 2.x builds and PC & $$anonymous$$ac however it doesn't work on IL2CPP builds
Thanks for providing the code. Nothing here jumps out at me as being a problem. What happens when AddRange is called on line 4? Does an exception occur?
No there is no exception it actually adds something mixed up and not what's on the list
It might be useful to try to scope down the problem, to deter$$anonymous$$e what gets added incorrectly. Also, you might be able to work around the problem by using a foreach loop and calling Add for each elements in the list, ins$$anonymous$$d of calling AddRange.
Your answer
![](https://koobas.hobune.stream/wayback/20220613192629im_/https://answers.unity.com/themes/thub/images/avi.jpg)