- Home /
eleven characters in an int[] array makes unity crash?
Soooo... I'm super new to unityscript so I'm sorry if this sounds like a dumb question (and sorry for my english as well, I'm a spanish-native speaker actually :/).
Anyway, I run into this weird problem: I was practicing a little of arrays with this extremely simple code which works perfectly:
var miarray = new int[2];
function Start () {
miarray[0]=1544444414;
miarray[1]=1244444412;
Debug.Log("array[] 0 = " + miarray[0]);
Debug.Log("array[] 1 = " + miarray[1]);
}
However, if I ever decide to add a single character to any of these two variables, Unity crashes! ... this is the code:
var miarray = new int[2];
function Start () {
miarray[0]=15444444141; //11 characters for unity to crash!
miarray[1]=1244444412;
Debug.Log("array[] 0 = " + miarray[0]);
Debug.Log("array[] 1 = " + miarray[1]);
}
Unity shuts down by itself and I get a "Unity Bug Reporter" window. So uhm... is this normal? (I'm using the free version of Unity for now by the way). Thanks in advance!
Also, I'd like to add that now I'm absolutely sure that what fafase says is the cause of the crash because when I give my variable a value of 5000000000 (a ten-character number but greater than 2billion) unity crashes again... so yeah...
Answer by fafase · Jul 12, 2014 at 01:38 AM
ints are limited as they are 32 bits, they can only hold values from . if you need bigger -2 to 2 billion.
http://msdn.microsoft.com/en-us/library/5kzh1b5w.aspx
Use uint and you get from 0 to 4 billions.
Floats can hold more but loses precision to some extent.
http://msdn.microsoft.com/en-us/library/b1e65aza.aspx
If you need a large integer value use a long
@fafase:
While that is true, Unity really shouldn't crash because of assigning a long literal to an int array element. Since UnityScript usually casts automatically that line should actually work. Even if not it should throw either a compiler error or a runtime exception ins$$anonymous$$d of crashing...
@el-rers:
You should file a bug report if you're sure that this is actually the cause of the crash.
I tried, but the thing gets stuck in "uploading report" :/
Actually it should even throw an error while saving the script.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Don't get my app running on device IOS5, Xcode 4.2 2 Answers
pick a random int with the value of 1 from an array 2 Answers
converting "int" to "string" 2 Answers