- Home /
C# list bug using addRange after call toString method only on unity ios
I found a strange behavior when using list addRange method after call the toString method; here is the test code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class ListAddRangeTest : MonoBehaviour {
void Start () {
try
{
TestAddRange();
}
catch (Exception e) {
ConsolePrintln(e.ToString());
}
}
private void TestAddRange()
{
int[] arr = new int[4];
for(int i=0; i<arr.Length; i++)
{
arr[i] = i;
}
List<int> list1 = new List<int>();
list1.AddRange(arr);
PrintList(list1);
Debug.Log(arr.ToString());
List<int> list2 = new List<int>();
list2.AddRange(arr);
PrintList(list2);
}
public void ConsolePrintln(string text) {
UnityEngine.Debug.Log(text);
}
public void PrintList(List<int> arr)
{
ConsolePrintln("Start print list--------");
for(int i=0; i<arr.Count; i++)
{
ConsolePrintln (arr[i].ToString());
}
ConsolePrintln("end print list--------");
}
}
after call the toString method, the the element in list2 sometime is all 0,but not always;this behavior only occurs on the ios platform,never occur in the editor;
I found a relate issue about the toString method is http://stackoverflow.com/questions/9929388/c-sharp-listobject-to-ilist-cast-bug-in-unity3d;I think they are the same problem;
So anyone can help me? It is so strange!!!!!
Answer by tw1st3d · Jul 25, 2013 at 03:25 AM
No idea what might be causing the problem except for maybe a list call error. Try this.
foreach(int i in arr)
{
ConsolePrintln(i.ToString());
}
ConsolePrintln("end print list--------");
result is same! here is the output
Start print list--------
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
0
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
1
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
2
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
3
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
end print list--------
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
System.Int32[]
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
Start print list--------
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
0
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
0
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
0
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
0
(Filename: /Applications/buildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/iPhonePlayer-armv7/UnityEngineDebug.cpp Line: 43)
end print list--------
Answer by z-Tree · Jul 25, 2013 at 03:58 AM
It seems ArrayList does not have the issue! I am using ArrayList instead of List, and test about 20 times, no problem!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Audio: how do I immediately play a new audioclip without delay(code included)? 2 Answers
How to move a GameObject into scene 1 Answer
Unity Push notification 0 Answers
Question on Mysterious XCode Crash 1 Answer